Find Prime Adam integers in the given range [ L , R ] | JavaScript 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
function reverse ( a ) { let rev = 0 ; while ( a != 0 ) { let r = a % 10 ; rev = rev * 10 + r ; a = parseInt ( a / 10 , 10 ) ; } return ( rev ) ; } function prime ( a ) { let k = 0 ; for ( let i = 2 ; i < a ; i ++ ) { if ( a % i == 0 ) { k = 1 ; break ; } } if ( k == 1 ) { return ( 0 ) ; } else { return ( 1 ) ; } } function adam ( a ) { let r1 = reverse ( a ) ; let s1 = a * a ; let s2 = r1 * r1 ; let r2 = reverse ( s2 ) ; if ( s1 == r2 ) { return ( 1 ) ; } else { return ( 0 ) ; } } function find ( m , n ) { if ( m > n ) { document . write ( " " + " " ) ; } else { let c = 0 ; for ( let i = m ; i <= n ; i ++ ) { let l = prime ( i ) ; let k = adam ( i ) ; if ( ( l == 1 ) && ( k == 1 ) ) { document . write ( i + " " ) ; } } } } let L = 5 , R = 100 ; find ( L , R ) ;