from time import clock import sys def multifactorial(n,k): count=0 mul=n i=1 n1= n - (k*i) start=clock() while n1 >= 1: mul=mul * n1 i=i+1 n1= n - (k*i) count=count+2 time=clock()-start total=sys.getsizeof(count)+sys.getsizeof(mul)+sys.getsizeof(i)+sys.getsizeof(n1)+sys.getsizeof(start) return mul,time,count f=open("in1_7.txt","r+") f1=open("out_7_1_7.txt","w") total=0 temp=[] data=[] time1=0 count1=0 for row in f: temp = row.split(',') ans,time,count=multifactorial(int(temp[0]),int(temp[1])) f1.write(str(ans)+"\n") time1=time1+time count1=count1+count total+=sys.getsizeof(time1)+sys.getsizeof(data)+sys.getsizeof(temp)+sys.getsizeof(count1)+sys.getsizeof(f)+sys.getsizeof(f1) f1.write("Time is "+str(time1)+"\n") f1.write("No of multiplications are "+str(count1)+"\n") f1.write("Program takes "+str(total)+" bytes of memory") f.close() f1.close() ##section1_7()