#4. Given two numbers x and y find pow(x,y) + pow(y,x) and pow(x,y) - pow(y,x) and pow(x,y) / pow(y,x) and pow(x,y) * pow(y,x) import sys import time f=open('c:\inputs\in4_5.txt','r') s=f.readline() i=s.index(",") x=int(s[0:i]) y=int(s[i+1:len(s)]) f.close() f1=open('out_15_sec4_5.txt','w') t1=time.clock() no_mul=0 def pow(x,y): global no_mul if(y==0): return 1 temp=pow(x,y/2) if(y%2==0): no_mul=no_mul+1 return temp*temp else: if(y>0): no_mul=no_mul+2 return x*temp*temp else: no_mul=no_mul+1 return (temp*temp)/x m1=pow(x,y) m2=pow(y,x) x=m1+m2 y=m1-m2 z=float(m1)/float(m2) m1=m1*m2 t2=time.clock() t=t2-t1 mem=sys.getsizeof(x)+sys.getsizeof(y)+sys.getsizeof(m1)+sys.getsizeof(m2)+sys.getsizeof(no_mul)+sys.getsizeof(z) f1.write(str(x)) f1.write("\n") f1.write(str(y)) f1.write("\n") f1.write(str(z)) f1.write("\n") f1.write(str(m1)) f1.write("\n") f1.write("no. of multiplications:") f1.write(str(no_mul)) f1.write("\n") f1.write("no. of additions=1") f1.write("\n") f1.write("Time used=") f1.write(str(t)) f1.write("seconds\n") f1.write("memory used=%d bytes"%mem) f1.close()