from time import clock import sys def perfect(From,To): global addcount global multicount global memory addcount=0 multicount=0 for n in range(From,To): max = int((n**0.5)) + 1 addcount+=1 tot = 1 q=0 for i in range (2, max): if ( (n % i) == 0 ): tot += i addcount+=1 q = int(n / i) if q > i: tot += q addcount+=1 if tot == n and tot!=1: outfile.write(str(n)+",") memory=sys.getsizeof(n)+sys.getsizeof(addcount)+sys.getsizeof(multicount)+sys.getsizeof(tot)+sys.getsizeof(q)+sys.getsizeof(max)+sys.getsizeof(i)+sys.getsizeof(From)+sys.getsizeof(To) infile=open("in7_4.txt",'r') From,To=infile.readline().split(',') From = int(From) To = int (To) outfile=open("out_14_7_4.txt",'w') start=clock() perfect(From,To) outfile.write("\n no of additions "+str(addcount)) outfile.write("\n no of multiplications "+str(multicount)) outfile.write("\n execution time "+str(clock()-start)) outfile.write("\n memory used "+str(memory)+" bytes") print "output file generated" infile.close() outfile.close()