# https://en.wikipedia.org/wiki/Gauss_circle_problem#Exact_forms N=lambda r:1+4*sum(r/(4*i+1)-r/(4*i+3) for i in range(999)) # sum results for z-slices of cubic lattice: for r in range(51): print sum(N(r*r-z*z) for z in range(-r,r+1)) # then golf a lot :)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).