from time import clock import sys def fibposition(n): global total a,b=0,1 i=2 count=0 for i in range(2,n+1): a,b=b,a+b count=count+1 total=total+sys.getsizeof(a)+sys.getsizeof(b)+sys.getsizeof(count) return b,count def fibseries(n): global total a,b=0,1 temp=[] count1=0 for k in range(0,n): temp.append(b) a,b=b,a+b count1=count1+1 total+=sys.getsizeof(a)+sys.getsizeof(b)+sys.getsizeof(temp)+sys.getsizeof(count1) return temp,count1 f=open("in2_7.txt","r+") f1=open("out_7_2_7.txt","w") total=0 data=[] ##arr=[] k=0 addcount=0 i = int(f.readline()) start = clock() data,count2=fibseries(i) for j in data: k,count3=fibposition(int(j)) addcount = addcount + count3 f1.write(str(k)+"\n") l = clock()-start total+=sys.getsizeof(data)+sys.getsizeof(k)+sys.getsizeof(i)+sys.getsizeof(addcount)+sys.getsizeof(start)+sys.getsizeof(count2)+sys.getsizeof(count3)+sys.getsizeof(l)+sys.getsizeof(f)+sys.getsizeof(f1) f1.write("Time is "+str(l)+"\n") f1.write("No of addition is "+str(count2+addcount)+"\n") f1.write("Memory required for program is "+str(total)+" bytes") f.close() f1.close()