fork download
  1. from fractions import gcd
  2.  
  3. def slope(a, b, r):
  4. lines = dict()
  5. for x in r:
  6. for y in r:
  7. c = a*x + b*y
  8. lines[c] = lines.get(c, 0) + 1
  9. count = 0
  10. for k in lines.values():
  11. count += 2**k - k - 1
  12. return count
  13.  
  14. def cnt(n):
  15. count = n*n + 1
  16. n = n
  17. r = range(0, n)
  18. for a in r:
  19. for b in r:
  20. if gcd(a, b) == 1:
  21. count += slope(a, b, r)
  22. if a*b != 0:
  23. count += slope(a, -b, r)
  24. return count
  25.  
  26. counts=[]
  27. for i in range(20):
  28. cur = cnt(i)
  29. counts.append(cur)
  30. print("{:3d}: {:10d}".format(i, cur))
  31. print(",".join(str(c) for c in counts[:12]))
  32.  
Success #stdin #stdout 0.83s 14792KB
stdin
Standard input is empty
stdout
  0:          1
  1:          2
  2:         11
  3:         54
  4:        191
  5:        554
  6:       1375
  7:       3206
  8:       6971
  9:      14850
 10:      31055
 11:      64766
 12:     134227
 13:     279962
 14:     582971
 15:    1217646
 16:    2544371
 17:    5321114
 18:   11116867
 19:   23221790
1,2,11,54,191,554,1375,3206,6971,14850,31055,64766