from time import clock import sys def fact(m): global total fact=m m1=m-1 count2=0 while m1>1: fact = fact * m1 m1 = m1-1 count2=count2+1 total+=sys.getsizeof(fact)+sys.getsizeof(m1)+sys.getsizeof(count2) return fact,count2 def primeno(n): global total arr=[2] count=0 count1=0 j=3 mul=0 mulcount=0 while count!=n-1: prime=1 l=int(j**0.5) for i in range(3,l+1,2): if j%i!=0: count1=count1+1 elif j%i==0: count1=count1+1 prime=0 break if prime==1: count=count+1 m,mul=fact(j) mulcount=mulcount+mul arr.append(m) j=j+2 total+=sys.getsizeof(arr)+sys.getsizeof(count)+sys.getsizeof(count1)+sys.getsizeof(j)+sys.getsizeof(mul)+sys.getsizeof(mulcount) return arr,count1,mulcount f=open("c:\inputs\in3_7.txt","r+") f1=open("out_7_sec3_7.txt","w") total=0 data=[] factorial=[] i = int(f.readline()) start=clock() data,div,multi = primeno(i) l= clock()-start for k in data: f1.write(str(k)+"\n") total+=sys.getsizeof(f)+sys.getsizeof(f1)+sys.getsizeof(total)+sys.getsizeof(data)+sys.getsizeof(factorial)+sys.getsizeof(div)+sys.getsizeof(multi) f1.write("No of division is "+str(div)+"\n") f1.write("No of multiplication is "+str(multi)+"\n") f1.write("Time is "+str(l)+"\n") f1.write("Memory required is "+str(total)+" bytes") f.close() f1.close()