def ModularExponent(a,j,p):
s=1
while j>0:
if j%2:
s=(s*a)%p
a=(a*a)%p
j=j//2
return s
def Btest(a,n):
s=0
t=n-1
while True:
s=s+1
t=t/2
if t%2==1:
break;
x=ModularExponent(a,t,n)
if x==1 or x==n-1:
return True
for i in range(1,s):
x=(x*x)%n
if x==n-1:
return True
return False
def MillRab(n):
a=random.randint(2,n-2)
return Btest(a,n)
def RepeatMillRab(n,k):
for i in range(0,k):
if MillRab(n)==False:
return False
return True
def PrintPrimes():
global cnt
print(2)
print(3)
n=5
cnt=0
while True:
if RepeatMillRab(n,math.floor(math.log(n,2))):
cnt+=1
print(n)
n=n+2
if n>=10000:
break
if __name__=="__main__":
start = time.time()
PrintPrimes()
end = time.time()
print(end-start)
print(cnt)