Reverse a Number using Function

 Coding Problem Keys 

 Reverse a Number using Function 

 Problem Statement 

A number 'n' is said to a Adam Number, if the reverse of the square of the number 'n' is square of the reverse of 'n'.

 Input Format 

The first line contains the number.

 Output Format 

Print Adam Number or Not Adam Number.

 Example Input/Output 1 

 Input 

12

 Output 

Adam Number

 Example 

Square of 12 = 144.
Reverse of 12 = 21.
Square of 21 is 441.
Reverse of 441 is 144.
Hence 12 is Adam Number.

 Note: Max Execution Time Limit: 25000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

def reverse(n):
    s=0
    while(n>0):
        s=s*10+n%10
        n//=10
    return s
n=int(input())
rev=reverse(n)
if n*n==reverse(rev*rev):
    print("Adam Number")
else:
    print("Not Adam Number")

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Anonymous said…
def reverseDigits(num) :
rev = 0
while (num > 0) :
rev = rev * 10 + num % 10
num //= 10

return rev

def square(num) :
return (num * num)

def checkAdamNumber(num) :

a = square(num)
b = square(reverseDigits(num))

if (a == reverseDigits(b)) :
return True
else :
return False

# Driver program to test above functions
num = 13
if (checkAdamNumber(num)) :
print "Adam Number"
else :
print "Not a Adam Number"


This works......

Popular Posts

Vaccine Distribution

String Rotation Odd and Even Positions

Highly Profitable Months

Largest Integer

Desktop Products

Words Starting with Upper Case

Find Maxima/Minima