# Program to find Fibonacci number of given n number using golden ratio formulae # Golden Ratio Formulae is # x = ((phy^n - (1-phy)^n))/sqr root(5) # Where x is nth fibonacci number , phy is a constant = 1.618034 , from time import clock import sys def fibo(n): memory=0 phi=(1+5**0.5)/2 X = int((phi**n - (1-phi)**n)/5**0.5) # From Golden ratio formulae memory= sys.getsizeof(X) + memory return X,memory f=open("in2_3.txt","r") temp=[] for row in f: temp=row.split(',') f.close() length=len(temp) f1=open("out_3_2_3.txt","w") for i in range(0,length): start=clock() fibo_N,memory=fibo(int(temp[i])) time_taken=clock()-start f1.write("\n " +temp[i]+ " = " + str(fibo_N)) f1.write("\n Time Taken = " + str(time_taken) +" seconds.") f1.write("\n Division = 1 .") f1.write("\n Memory =" + str(memory) + " bytes \n") f1.close()