Circular Prime Number is a number whose all-circular permutations are Prime Numbers.
Prime Number is a number which is only divisible by 1 and the number itself i.e., it has no factors other than 1 and itself.
Example 1: 113. All possible circular permutations are 113, 131, 311. All of these are Prime Numbers. Hence it is a Circular Prime Number.
Example 2: 115. All possible circular permutations are 115, 151, 511. Since 115 and 511 are not Prime Numbers. Hence it is not a Circular Prime Number.
Java
import java.util.*;
public class CircularPrimeNumber
{
public static void main(String args[])
{
int n=0,r=0,q=0,l=0,nCopy=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
nCopy=n;
while(n>0)
{
l++;
n=n/10;
}
n=nCopy;
for(int i=1;i<=l;i++)
{
for(int j=2;j<n;j++)
{
if(n%j==0)
{
System.out.println(n+" is not a Circular Prime Number");
System.exit(1);
}
}
r=n%10;
q=n/10;
n=(r*(int)Math.pow(10,l-1))+q;
}
System.out.println(n+" is a Circular Prime Number");
}
}
Java