from time import clock import sys def magic(): InFile=open('in_sec13_1.txt','r') OutFile=open('out_31_sec13_1.txt','w') start=clock() n,m=InFile.readline().split(",") n=int(n) m=int(m) for n in range(n,m+1): Sum = n* ((n * n)+1)/2 if(n%2==0): n+=1 continue else: matrix =[[0 for col in range(n)] for row in range(n)] Middle=(n/2) currentRow=0 matrix[currentRow][Middle]=1 for i in range(2,(n*n)+1): top=(currentRow-1)%n right=(Middle+1) %n if(matrix[top][right]==0): matrix[top][right]=i else: top=(currentRow+1)%n right=(Middle) %n matrix[top][right]=i currentRow=top Middle=right OutFile.write("n= "+str(n)+ " Sum= "+str(Sum)+"\n") for i in range(0,n): for j in range(0,n): OutFile.write(str(matrix[i][j])+" ") OutFile.write(str("\n")) OutFile.write(str("\n")) OutFile.write("\nTotal Excution Time : "+str(clock()-start)) total = sys.getsizeof(InFile) + sys.getsizeof(OutFile)+ sys.getsizeof(start)+ sys.getsizeof(matrix)+ sys.getsizeof(n)+ sys.getsizeof(m) OutFile.write("\ntotal Memory--- : "+str(total)) InFile.close() OutFile.close() magic()