Skip to content

Instantly share code, notes, and snippets.

@aburousan
Created December 7, 2022 15:44
Show Gist options
  • Save aburousan/2e3c0563a2ba2858a09cea4d932b727d to your computer and use it in GitHub Desktop.
Save aburousan/2e3c0563a2ba2858a09cea4d932b727d to your computer and use it in GitHub Desktop.
from math import floor, sqrt
def lattice_inside(N):#give square of the radius,i.e., R = \sqrt(N)
summ = 0;
loop_no = int(N/3) + 2
for i in range(0,loop_no+1):
a = floor(N/(3*i+1))
b = floor(N/(3*i+2))
# print(a,b,i)
summ = summ + 6*(a-b)
return summ + 1
def lattice_on(N):
return lattice_inside(N)-lattice_inside(N-1)
print(lattice_on(7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment