Circular Prime
✹ A Number is said to be a Circular Prime if the Number generated at each intermediate step when cyclically permuting its digits will be Prime.
Examples : 113, 197, 199, 337, 1193, 3779, 11939, 19937 etc
i.e. 113 -> 131 -> 311 is circular prime.
import java.util.*;
class Circular_Prime
{
public static void main(String args[])
{
int dc=0, n1,n2,i,j,m,c,f=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number = ");
int n=sc.nextInt();
n1=n;
n2=n;
//Count the Number of Digits
while(n1>0)
{
dc++;
n1=n1/10;
}
//For Loop Counted as per Number of Digit
for(i=1;i<=dc;i++)
{
n2=(n2%10)*(int)Math.pow(10,(dc-1))+(n2/10);
//(131%10)*10^(3-1)+131/10
System.out.println(n2);
m=n2;
c=0;
//Prime Number Checking at every interval
for(j=1;j<=m;j++)
if(m%j==0)
c++;
if(c>2)
f=1;
}
//Circular Prime Checking
if(f==0)
System.out.println("Circular Prime");
else
System.out.println("Not Circular Prime");
}
}
No comments