











Automorphic number using Python
Automorphic Number:
In mathematics, an automorphic number (sometimes referred to as a circular number) is a natural number in a given number base b whose square end in the same digits as the number itself.
Example:
- n=25,
- 25*25=625
- Output: Automorphic
- n=70,
- 70*70=4900
- Output: Not Automorphic


Implementation:
- Evaluate the square of the given number (sq).
- Loop until the given number becomes zero.
- Check if digit on the unit place of the given number is equal to digit on the unit place of the square number.
- If the above condition holds true , reduce the number as n=n/10 and sq=sq/10.
Else return false.
Python Code:
1st Approach
#enter the number to check
print(‘Enter the number:’)
n=int(input())
sq=n*n #square of the given number
co=0 #condition variable
while(n>0): #loop until n becomes 0
if(n%10!=sq%10):
print(‘Not Automorphic’)
co=1
break # come out of the loop if the above condition holds true
#reduce n and square
n=n//10
sq=sq//10
if(co==0):
print(‘Automorphic’)
2nd Approach
n=int(input(“Enter any number”))
x=n**2
a=str(n)
b=str(x)
y=len(a)
z=len(b)
if(z-b.find(a)==y):
print(“Automorphic”)
else:
print(“Not automorphic number”)
Output:
Enter the number:
376
Automorphic
Login/Signup to comment