Prime Adam
Prime Adam
A Prime-Adam integer is n positive integer (without lending zeros) which is a prime as well as an Adam
number.
Prime number: A number which has only two factors, i.e. J and the number itself. Example: 2, 3, 5, 7 . .
. etc.
Adam number: The square of n number and the square of its reverse and reverse to each other.
Example: If n=13 and reverse of 'n'= 31, then,
(13)2 = 169 (31)2 = 961
961 which is reverse of 169 thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all Prime-Adam
integers that are in the range between m and n (both inclusive) and output them along with the
frequency, in the format given below:
Test your program with the following data and some random data:
Example 1
INPUT: m=10 n = 100
OUTPUT: THE PRIME-ADAM INTEGERS ARE: 11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2 THE PRIME-ADAM INTEGERS ARE: 11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
INPUT: m = 100 n =200
OUTPUT: THE PRIME-ADAM INTEGERS ARE: 101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT: m = 50 n = 70
OUTPUT: THE PRIME-ADAM INTEGERS ARE:
FREQUENCY OF PRIME-ADAM INTEGERS IS: O
Example 4
INPUT: m = 700 n =450
OUTPUT: INVALID INPUT.
ALGORITHM
• MAIN Function
• START
• Prompt the user to input a number.
• Read the number int n from the user.
Prime Check Function:
• Call the function isPrime(n) to check if int n is a prime number.
o Define isPrime(n):
▪ If n is less than or equal to 1, return false.
▪ For each integer iii from 2 to the square root of n:
▪ If n is divisible by iii (i.e., n%i==0n \% i == 0n%i==0), return false.
▪ If no divisors are found, return true.
Adam Number Check Function:
• Call the function is_adam(n) to check if n is an Adam number.
o Define is_adam(n):
▪ Reverse the digits of n to get rev.
▪ Square both n and rev to get their squares.
▪ Reverse the digits of the squares of n and rev.
▪ If reverse of n square is equal to square of n reverse, return true.
Otherwise, return false.
Back to Main after calling to print the result:
• If both isPrime(n) and is_adam(n) return true, print "It is a prime Adam number."
• Otherwise, print "It is not a prime Adam number."
• STOP
CODE
import java.util.*;
class prime_adam
{
public static void main()
{
Scanner obj = new Scanner(System.in);
System.out.println("input the no.");
int n = obj.nextInt();
if(isPrime(n) && is_adam(n))
{
System.out.println("It is a prime adam no.");
}
else
{
System.out.println("It is not a prime adma no.");
}
}