Maybe it would be easier to count the number of lines in nxn which pass through more than two points.
That's equivalent to asking how many 2ix2j rectangles there are in nxn, where i and j are relatively prime, except that it would overcount the lines that pass through 3 or more points.
Let R_k = the number of ki x kj rectangles in nxn, where i and j are relatively prime.
The number of lines passing through at least three points in nxn is R_2 + R_3 - R_4 + R_3...

