1 #n**0.5 2 def comp(n,i): 3 for i in range(2,int(n**0.5)+1): 4 if(n%i==0): 5 return False 6 else: 7 return True 8 import time 9 t=time.clock() 10 j=1 11 a=[2] 12 for n in range(3,100000,2): 13 if(comp(n,2)==True): 14 j=j+1 15 a.append(n) 16 print(j) 17 print("{}".format(time.clock()-t)) 18 19 #list9999900000--10000000000 20 def comp1(n,i): 21 for i in a: 22 if(n%i==0): 23 return False 24 else: 25 return True 26 import time 27 g=time.clock() 28 j=0 29 for n in range(9999900001,10000000000,2): 30 if(comp1(n,2)==True): 31 j=j+1 32 print(j) 33 print("{}".format(time.clock()-g)) 34 35 #list2-10000000000 36 def comp2(n,i): 37 for i in a: 38 if(i>int(n**0.5)+1): 39 return True 40 if(n%i==0): 41 return False 42 else: 43 return True 44 import time 45 k=time.clock() 46 j=1 47 for n in range(3,10000000000,2): 48 if(comp2(n,2)==True): 49 j=j+1 50 print(j) 51 print("{}".format(time.clock()-k))
#n**0.5def comp(n,i): for i in range(2,int(n**0.5)+1): if(n%i==0): return False else: return Trueimport timet=time.clock()j=1a=[2]for n in range(3,100000,2): if(comp(n,2)==True): j=j+1 a.append(n)print(j)print("{}".format(time.clock()-t))
#list9999900000--10000000000def comp1(n,i): for i in a: if(n%i==0): return False else: return Trueimport timeg=time.clock()j=0for n in range(9999900001,10000000000,2): if(comp1(n,2)==True): j=j+1print(j)print("{}".format(time.clock()-g))
#list2-10000000000def comp2(n,i): for i in a: if(i>int(n**0.5)+1): return True if(n%i==0): return False else: return Trueimport timek=time.clock()j=1for n in range(3,10000000000,2): if(comp2(n,2)==True): j=j+1print(j)print("{}".format(time.clock()-k))