Adam Number | Practice | GeeksforGeeks

Given a number N, write a program to check whether given number is Adam Number or not.
Adam number is a number when reversed, the square of the number and the square of the reversed number should be numbers which are reverse of each other.
 
Example 1: 
Input: 
N = 12
Output:
YES
Explanation:
122 = 144 and 212 = 441. 144 reversed 
gives 441, So, it's an Adam Number.
Example 1: 
Input: 
N = 14
Output:
NO
Explanation:
142 = 196. 196 reversed gives 691,
which isn't equal to 412 So,
it's not an Adam Number.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function checkAdamOrNot() which takes an Integer N as input and returns the answer as "YES" if it is a Adam, number. Otherwise, returns "NO".
 
Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 104
0
badgujarsachin833 months ago
 string checkAdamOrNot(int N) {
        // code here
        long long int a=N*N;
        int reverse=0;
        int temp=N;
        while(temp>0){
            reverse=reverse*10+(temp%10);
            temp/=10;
        }
        long long int ans=reverse*reverse;
        long long int ok=0;
        while(ans>0){
            ok=ok*10+(ans%10);
            ans/=10;
        }
        if(ok==a){
            return "YES";
        }else{
            return "NO";
        }
        
    }
+1
rdm1233 months ago
def checkAdamOrNot(self, N):
        a=N*N
        s=str(N)[::-1]
        b=int(s)*int(s)
        if(str(a)==str(b)[::-1]):
            return "YES"
        return "NO"
0
SACHIN KUMAR1 year ago
SACHIN KUMAR
 public:    string checkAdamOrNot(int N) {        long long int sq = N*N;        int temp = N;        int reverse = 0 ;        while(temp)        {            int r = temp % 10;            reverse = (reverse * 10) + r;             temp /= 10;        }        long long int r_sq = reverse*reverse;        long long int sq_reverse = 0;         while(r_sq)        {            int r = r_sq % 10;            sq_reverse = (sq_reverse * 10) + r;            r_sq /= 10;        }        if(sq == sq_reverse)        {            return "YES";        }        else        {            return "NO";        }    }
0
Sreedhar Karanam2 years ago
Sreedhar Karanam
Python solution (0.07 sec):class Solution:    def checkAdamOrNot(self, N):        # code here         if(str(N**2)==str(int(str(N)[::-1])**2)[::-1]):            return "YES"        else:            return "NO"
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.