fork download
  1. def isAutomorphic(N):
  2.  
  3. # Store the square
  4. if N < 0:
  5. N = -N
  6. sq = N * N
  7.  
  8. # Start Comparing digits
  9. while (N > 0) :
  10.  
  11. # Return false, if any digit of N doesn't
  12. # match with its square's digits from last
  13. if (N % 10 != sq % 10) :
  14. return False
  15.  
  16. # Reduce N and square
  17. N //= 10
  18. sq //= 10
  19.  
  20. return True
  21.  
  22. # Driver code
  23. N = 5
  24. if isAutomorphic(N) :
  25. print ("Automorphic")
  26. else :
  27. print ("Not Automorphic")
  28.  
Success #stdin #stdout 0.03s 9584KB
stdin
Standard input is empty
stdout
Automorphic