Navbar

Saturday, 28 March 2020

ISC COMPUTER PRACTICAL - 2020 - QUESTION 1 (PRIME ADAM NUMBER)

ISC 2020 Computer Practical Question 1–Prime Adam Integer.

-WRITTEN BY CODERGURUJI

Prime-Adam integer is a positive integer (without leading zeroes) which is a prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself. Example: 2, 3, 5, 7, etc.
Adam number: The square of a number and the square of its reverse are reverse to each other. Example: If n = 13 and reverse of ‘n’ is 31, then, 132 = 169, and 312 = 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 = 5
n = 100

OUTPUT:

The Prime-Adam integers are:
11, 13, 31
Frequency of Prime-Adam integers is: 3
Example 2:

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:
NIL
Frequency of Prime-Adam integers is: 0
Example 4:

INPUT:

m = 700
n = 450
OUTPUT:
Invalid Input.

SOLUTIONS :

import java.util.*;
class coderguruji
{
    public static void main(String coderguruji[])
    {      
        int p=0,p1=0,c=0,s=0,d=0,s1=0,f=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("enter M and N");
        int m=sc.nextInt();
        int n=sc.nextInt();
        if(m>n)
        {
            System.out.println("INVALID INPUT");
        }
        else
        {
        int a[]=new int[1000];
        int b[]=new int[1000];
        System.out.println("THE PRIME-ADAM INTEGERS ARE:");
        for(int i=m;i<n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)           ///for finding prime number
                {
                    c++;
                }
            }
                if(c==2)
                {
                    a[p]=i;     ////storing all prime number in array
                    p++;
                    c=0;
                }
                else
                {
                    b[p1]=i;
                    p1++;
                    c=0;
                }
            }
        for(int i=0;i<p;i++)
            {
               int w=a[i];
                while(w>0)
                {
                    int b1=w%10;
                    s=s*10+b1;         ///for reversing prime numbers
                    w=w/10;
                   
                }
                d=a[i]*a[i];      ///Square of prime numbers
                int sum=s*s;      ///Square of reverse numbers
              int  sum1=sum;
                while(sum1>0)
                {
                    int b2=sum1%10;
                    s1=s1*10+b2;         ///reverse of Square of reversed numbers
                    sum1=sum1/10;
                   
            }
            if(d==s1)      ///checking numbers is prime adam number
             {
                 f++;
                System.out.println(a[i]+" ");     ///printing of prime adam number
                 d=0;
                s1=0;
                s=0;
            }
                else
                {
                d=0;
                s1=0;
                s=0;
            }
        }
        System.out.println("FREQUENCY OF PRIME-ADAM INTEGERS IS:"+f);
    }
}
            }
        -----------------------------------------end----------------------------------------------