(Updated in response to comments below:)
I wrote a short Python program to count lines in small grids, which gave me enough data to search OEIS and find the answer at A018808A018809.
Here is the code; the only real trick is to do everything in projective coordinates rather than staying in the Cartesian world.
# Count lines through exactly two points in an n*n grid of points # dictionary mapping lines to the number of times they occur lines = [] {} def meet((a,b,c),(d,e,f)): """The line ""Line through two points , or the point on two lines.""" return ((b*f-c*e,c*d-a*f,a*e-b*d)) def same(l1,l2): """Do these two triples of coordinates represent the same line?""" return meet(l1,l2)==(0,0,0) def add(l1): """Test whether a triple represents a new line, and if so add it to ""Update the list.""number of times line l1 has been generated.""" if l1 == (0,0,0): return for l2 in lines: if same(l1,l2): lines[l2] += 1 return lines.append(l1) lines[l1] = 1 for n in range(1,7)range(1,8): lines = {} for a in range(n): for b in range(n): for c in range(n): for d in range(n): add(meet((a,b,1),(c,d,1))) goodlines = 0 for line,count in lines.items(): if count == 2: goodlines += 1 print len(lines)goodlines

