fantho69

magicsquare2.py

Jul 14th, 2021 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. def countdoubleoccurrances(n,d):
  2.     count=0
  3.     while (n>0):
  4.         if(n%10==d):
  5.             count+=1
  6.             if(count>2):
  7.                 return -1
  8.         n=n//10
  9.     return count
  10. def magicsquare(n):
  11.     for i in range(0,9):
  12.         if(countdoubleoccurrances(n*n,i)!=2):
  13.             return False
  14.     return True
  15. i=1
  16. for n in range(3164211346,9994386752):
  17.         if(magicsquare(n)):
  18.             string=str(i)+" "+str(n)+"  "+str(n*n)
  19.             print(string)
  20.             i+=1
Add Comment
Please, Sign In to add comment