A288797 Square array a(p,q) = p^2 + q^2 - 2*p - 2*q + 2*gcd(p,q), p >= 1, q >= 1, read by antidiagonals.
0, 1, 1, 4, 4, 4, 9, 5, 5, 9, 16, 12, 12, 12, 16, 25, 17, 13, 13, 17, 25, 36, 28, 20, 24, 20, 28, 36, 49, 37, 33, 25, 25, 33, 37, 49, 64, 52, 40, 36, 40, 36, 40, 52, 64, 81, 65, 53, 45, 41, 41, 45, 53, 65, 81, 100, 84, 72, 64, 52, 60, 52, 64, 72, 84, 100
Offset: 1
Examples
Table begins: 0 1 4 9 16 25 ... 1 4 5 12 17 28 ... 4 5 12 13 20 33 ... 9 12 13 24 25 36 ... 16 17 20 25 40 41 ... 25 28 33 36 41 60 ... ... ... ... ... ... ... ...
Links
- Luc Rousseau, Illustration for p=6, q=4
Programs
-
Mathematica
A[p_, q_] := p^2 + q^2 - 2*p - 2*q + 2*GCD[p, q]; (* or, checking without the formula: *) okQ[{a_, b_}, p_, q_] := Module[{r2 = p^2 + q^2}, 0 <= a*q - b*p <= r2 && 0 <= a*p + b*q <= r2 && 0 <= a*q - b*p + q <= r2 && 0 <= a*p + b*q + p <= r2 && 0 <= a*q - (b + 1)*p <= r2 && 0 <= a*p + b*q + q <= r2 && 0 <= (a + 1)*q - (b + 1)*p <= r2 && 0 <= a*p + b*q + p + q <= r2]; A[p_, q_] := Module[{r}, r = Reduce[okQ[{a, b}, p, q], {a, b}, Integers]; If[r[[0]] === And, 1, Length[r]]]; Flatten[Table[A[p - q + 1, q], {p, 1, 11}, {q, 1, p}]] (* Jean-François Alcover, Jun 17 2017 *)
-
PARI
a(p,q)=p^2+q^2-2*p-2*q+2*gcd(p,q) for(n=2,12,for(p=1,n-1,{q=n-p;print(a(p,q))}))
Comments