Automorphic numbers are numbers having "n" digits such that the last n digits of the square of the number will be the number itself. Write an algorithm and the subsequent Python code to check if the given number is automorphic. Write a function to find the square of a given number.. For example, 25 is a 2 digit automorphic number with a square of 625 and 376 with its square 141376, is a 3 digit automorphic number.
Input Format
First line contains the number to be checked
Output Format
Print Automorphic or Not automorphic
Input Format
First line contains the number to be checked
Output Format
Print Automorphic or Not automorphic
Input:
The number
Processing Involved:
def automorphic(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Automorphic')
else:
print('Not automorphic')
Output:
Display whether the number is automorphic or not
Program:
def automorphic(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Automorphic')
else:
print('Not automorphic')
n = int(input())
automorphic(n)
Algorithm:
Step1. Define the function automorphic with one parameter n
Step1.1 assign temp as an empty string and length as length of the number n
Step1.2 check if the last n digits of the square of n is the number n if true the display automorphic else display not automorphic
Step2. get the number n
Step3. Call the function automorphic to check if n is automorphic or not
Step4. End
No comments:
Post a Comment