Find Prime Adam integers in the given range [ L , R ] | Python3 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
def reverse ( a ) : NEW_LINE INDENT rev = 0 ; NEW_LINE while ( a != 0 ) : NEW_LINE INDENT r = a % 10 ; NEW_LINE rev = rev * 10 + r ; NEW_LINE a = a // 10 ; NEW_LINE DEDENT return ( rev ) ; NEW_LINE DEDENT def prime ( a ) : NEW_LINE INDENT k = 0 ; NEW_LINE for i in range ( 2 , a ) : NEW_LINE INDENT if ( a % i == 0 ) : NEW_LINE INDENT k = 1 ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( k == 1 ) : NEW_LINE INDENT return ( 0 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( 1 ) ; NEW_LINE DEDENT DEDENT def adam ( a ) : NEW_LINE INDENT r1 = reverse ( a ) ; NEW_LINE s1 = a * a ; NEW_LINE s2 = r1 * r1 ; NEW_LINE r2 = reverse ( s2 ) ; NEW_LINE if ( s1 == r2 ) : NEW_LINE INDENT return ( 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( 0 ) ; NEW_LINE DEDENT DEDENT def find ( m , n ) : NEW_LINE INDENT if ( m > n ) : NEW_LINE INDENT print ( " INVALID INPUT " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT c = 0 ; NEW_LINE DEDENT for i in range ( m , n ) : NEW_LINE INDENT l = prime ( i ) ; NEW_LINE k = adam ( i ) ; NEW_LINE if ( ( l == 1 ) and ( k == 1 ) ) : NEW_LINE INDENT print ( i , " TABSYMBOL " , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT L = 5 ; R = 100 ; NEW_LINE find ( L , R ) ; NEW_LINE