Find Prime Adam integers in the given range [ L , R ] | C ++ program to find all prime adam numbers in the given range ; Reversing a number by taking remainder at a time ; Function to check if a number is a prime or not ; Iterating till the number ; Checking for factors ; Returning 1 if the there are no factors of the number other than 1 or itself ; Function to check whether a number is an adam number or not ; Reversing given number ; Squaring given number ; Squaring reversed number ; Reversing the square of the reversed number ; Checking if the square of the number and the square of its reverse are equal or not ; Function to find all the prime adam numbers in the given range ; If the first number is greater than the second number , print invalid ; Iterating through all the numbers in the given range ; Checking for prime number ; Checking for Adam number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int reverse ( int a ) { int rev = 0 ; while ( a != 0 ) { int r = a % 10 ; rev = rev * 10 + r ; a = a / 10 ; } return ( rev ) ; } int prime ( int a ) { int k = 0 ; for ( int i = 2 ; i < a ; i ++ ) { if ( a % i == 0 ) { k = 1 ; break ; } } if ( k == 1 ) { return ( 0 ) ; } else { return ( 1 ) ; } } int adam ( int a ) { int r1 = reverse ( a ) ; int s1 = a * a ; int s2 = r1 * r1 ; int r2 = reverse ( s2 ) ; if ( s1 == r2 ) { return ( 1 ) ; } else { return ( 0 ) ; } } void find ( int m , int n ) { if ( m > n ) { cout << " ▁ INVALID ▁ INPUT ▁ " << endl ; } else { int c = 0 ; for ( int i = m ; i <= n ; i ++ ) { int l = prime ( i ) ; int k = adam ( i ) ; if ( ( l == 1 ) && ( k == 1 ) ) { cout << i << " TABSYMBOL " ; } } } } int main ( ) { int L = 5 , R = 100 ; find ( L , R ) ; return 0 ; }