0% found this document useful (0 votes)
431 views4 pages

Prime Adam

Uploaded by

Saksham14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
431 views4 pages

Prime Adam

Uploaded by

Saksham14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Question

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.");
}
}

static boolean isPrime(int a)


{
int c=0;
for(int i = 1;i<=a;i++) //prime
{
if(a%i == 2)
c++;
}
if(c != 2)
return true;
else
return false;
}

static boolean is_adam(int n )


{
int rev = num_rev(n*n);
int rev2 = num_rev(n);
int sq= rev2 *rev2;
if(sq == rev)
{
return true;
}
else
{
return false;
}
}

static int num_rev(int n)


{
int rev=0, rem=0;
while (n > 0)
{
rem = n % 10;
rev = (rev * 10) + rem;
n = n / 10;
}
return rev;
}
}

You might also like