import csv import math import time from decimal import * import sys tinitial = time.time() f = open('out_23_sec3_3.txt', 'w') print ("",end="",file=f) f.close() tinitial = time.time() def prime(x): ps=[] k=0 f = open('out_23_sec3_3.txt', 'w') print(2,end=',',file=f) print(3,end=',',file=f) ps.append(2) ps.append(3) pp=3 # print(int(x)) while (int(x)!=len(ps)): pp+=2 test=True sqrtpp=math.sqrt(pp) for a in ps: if a>sqrtpp: break if pp%a==0: test=False break if test: k=k+1 # print (fibprimecheck(pp)) if(fibprimecheck(int(((Decimal(Decimal((1+Decimal(math.sqrt(5)))/2)**(pp))-(Decimal(Decimal((1-Decimal(math.sqrt(5)))/2)**(pp)))))/Decimal((math.sqrt(5)))))): print (int(((Decimal(Decimal((1+Decimal(math.sqrt(5)))/2)**(pp))-(Decimal(Decimal((1-Decimal(math.sqrt(5)))/2)**(pp)))))/Decimal((math.sqrt(5)))),end=",",file=f) ps.append(pp) print (" ",file=f) print ("No of divisions:",int(row[0])*k,file=f) f.close() return ps def fibprimecheck(y): # print(int(y)) test=True sqrty=math.sqrt(y) # print (int(sqrty)) for a in range(int(sqrty)): if y%(a+2)==0: test=False break return test infile= open('c:\inputs\in3_3.txt',"r") # Read in the data csv_reader = csv.reader(infile) for row in csv_reader: prime(int(row[0])) f = open('out_23_sec3_3.txt', 'a') print ("Execution Time : ",(time.time()-tinitial)," Seconds",file=f) print ("Memory Used: ",sys.getsizeof(int)*(int(row[0]))+sys.getsizeof(int)*5,file=f) infile.close() f.close()