forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circular_prime.java
54 lines (51 loc) · 1.17 KB
/
circular_prime.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class circular_prime
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number to check: ");
int n=Integer.parseInt(br.readLine());
int nn=n,c=0,n1=n,n2=n,f=0;
while(nn>0)
{
c++;
nn/=10;
}
do
{
n=n1;
if(!isprime(n))
{
f=1;
break;
}
int r=n%10;
int q=n/10;
n1=(int)Math.pow(10,c-1)*r+q;
if(n1!=n2)
{
System.out.println(n1);
}
}
while(n1!=n2);
if(f==1)
System.out.println("Not circular prime");
else
System.out.println("circular prime");
}
static boolean isprime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
return c == 2;
}
}