from time import clock import math,sys def fun(m,n): global c if m==1: if n==1: return 1 else: return fun(n,m) else: c+=1 return fun(math.floor((m)/2),n)+fun(m-math.floor((m)/2),n) def main(): try: start=clock() f=open("14_4.txt","r") f1=open("out_34_14_4.txt","w") s=f.read() f.close() s1=s.split(",") m=int(s1[0]) n=int(s1[1]) global c c=0 p=fun(m,n) end=clock() f1.write("Total pieces are : %d" %p) f1.write("\nTotal breaks are : %d" %c) f1.write("\nTime taken by the program is : %f seconds" %(end-start)) mem=sys.getsizeof(f)+sys.getsizeof(f1)+sys.getsizeof(s)+sys.getsizeof(s1)+sys.getsizeof(m)+sys.getsizeof(n)+sys.getsizeof(c)+sys.getsizeof(p) f1.write("\nMemory used by the program is : %d bytes." %mem) f1.close() except IOError: print "File not found in the directory" main()