%I
%S 0,6,28,86,200,418,748,1282,2040,3106,4492,6394,8744,11822,15556,
%T 20074,25456,32086,39724,48934,59456,71554,85252,101250,119040,139350,
%U 161932,187254,215136,246690,280916,319346,361328,407302,457180,511714,570232
%N Total number of line segments between points visible to each other in a square n X n lattice.
%C A line segment joins points (a,b) and (c,d) if the points are distinct and gcd(ca,db)=1.
%H S. Mustonen, <a href="http://www.survo.fi/papers/LinesInGrid2.pdf">On lines going through a given number of points in a rectangular grid of points</a> [From _Seppo Mustonen_, May 13 2010]
%F a(n) = A114043(n)  1.
%e The 2 x 2 square lattice has a total of 6 line segments: 2 vertical, 2 horizonal and 2 diagonal.
%t Table[cnt=0; Do[If[GCD[ca,db]<2, cnt++ ], {a,n}, {b,n}, {c,n}, {d,n}]; (cntn^2)/2, {n,20}]
%t Contribution from _Seppo Mustonen_, May 13 2010: (Start)
%t (* This recursive code is much more efficient. *)
%t a[n_]:=a[n]=If[n<=1,0,2*a1[n]a[n1]+R1[n]]
%t a1[n_]:=a1[n]=If[n<=1,0,2*a[n1]a1[n1]+R2[n]]
%t R1[n_]:=R1[n]=If[n<=1,0,R1[n1]+4*EulerPhi[n1]]
%t R2[n_]:=(n1)*EulerPhi[n1]
%t Table[a[n],{n,1,37}]
%t (End)
%Y Cf. A141224.
%K nonn
%O 1,2
%A _T. D. Noe_, Jun 17 2008
