from time import clock import math,sys def main(): try: start=clock() f=open("13_4.txt","r") f1=open("out_34_13_4.txt","w") n=int(f.read()) f.close() nop=0 #To count the number of toggling in the whole program. nopen=0 #To count the number of opened doors at the end of the program. lstopen=[] #To store the positions of doors that ar opened. for d in xrange(1,n+1): c=0 for k in xrange(1,n+1): if d%k==0: c+=1 nop+=c if c%2==1: nopen+=1 lstopen.append(str(d)) end=clock() f1.write("Total number of opened doors : %d\n" %nopen) f1.write("Total number of toggling done: %d\n" %nop) f1.write("Opened doors are: \n") f1.write(','.join(lstopen)) f1.write("\nTime taken by the program is : %f seconds" %(end-start)) mem=sys.getsizeof(f)+sys.getsizeof(f1)+sys.getsizeof(n)+sys.getsizeof(nop)+sys.getsizeof(nopen)+sys.getsizeof(lstopen)+sys.getsizeof(d)+sys.getsizeof(c)+sys.getsizeof(k) f1.write("\nMemory used by the program is : %d bytes." %mem) f1.close() except IOError: print "File not found in the directory." main()