-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathPrimeAdam.java
65 lines (62 loc) · 1.43 KB
/
PrimeAdam.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
class PrimeAdam
{
int m,n; //declaration
public PrimeAdam()
{
m=n=0;
}
void input() //input lower and upper range
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter m and n");
m=sc.nextInt();
n=sc.nextInt();
}
int prime(int no) //check for prime
{
int c=0; //declaration
for(int i=1;i<=no;i++)
{
if(no%i==0)
c++;
}
return c;
}
int adam(int no) //check for adam
{
int s=0,p=1,s1=0; //declaration
while(no>0)
{
s=s*10+(no%10);
no=no/10;
}
p=s*s;
while(p>0)
{
s1=s1*10+(p%10);
p=p/10;
}
return s1;
}
void print() //printing prime-adam numbers between m and n
{
int c=0; //declaration
for(int i=m;i<=n;i++)
{
if((prime(i)==2) && ((adam(i))==(i*i)))
{
System.out.print(i+" ");
c++;
}
}
System.out.println();
System.out.print("FREQUENCY OF PRIME-ADAM INTEGERS IS="+c);
}
public static void main()
{
PrimeAdam ob=new PrimeAdam(); //creating object ob
ob.input(); //calling function
ob.print(); //calling function
}
}