This world is full of beautiful numbers. But, why are prime numbers intriguing? In this chaotic world, matter made up of prime numbers forms a stable entity. 2,3,5,7,11 and so on are the stable entities amongst their unstable composite numbers such as 6, 16, 32, and so on which can always break into multiples. Therefore, we always say that we live in a prime number world.
What is a Circular Prime?
A circular prime is a prime number that remains to be a prime even when rotated cyclically. For example, 197 is a prime number, and when rotated to be 971 or 719; both these are prime numbers too. Similarly, take the number 1193 and it is a circular prime number. 1931, 9311, and 3119 are prime numbers too. Another example of a circular prime is the number 19937 – 19937,99371,93719,37199 and 71993 are primes.
Circular prime numbers are extremely rare in the number world. Circular primes are made up of 1,3,7 and 9. They don’t contain 2 or 5 in the number as they’re divisible when present at the end of the number.
- Two digits Circular prime numbers do not contain digits 0, 2, 4, 5, 6 or 8. As numbers containing such digits at its unit’s place are divisible by either 2 or 5.
- Every prime repunit is a circular prime.
- Every permutable prime is also a circular prime. But every circular prime is not a permutable prime.
How to check if a number is circular prime or not?
Simple pre-checks:
- If the input is a single digit, it is circular if it is prime.
- If the number contains one of the digits 0, 2, 4, 5, 6, or 8, it is not a circular prime. Assumes more than one digit.
Logic to check if a number if circular prime or not:
Step 1: Start
Step 2: Read n Value
Step 3: Declare p, leng, i, dup
Step 4: Copy the n Value to dup variable
Step 5: Assign p=0, leng=0
Step 6: First partition the number into its digits.
Step 7: Make all possible rotations with those digits. Then, check whether or not each possible rotation is a prime number.
Step 8: If all the possible rotation is proved Prime number
Step 9: Print the given number is “Circular Prime Number” otherwise, Print the given number is “Not Circular Prime Number”
Step 10: Stop
C++ Program to print circular primes less than a limit
Below is the C++ code for kids to play around with circular primes.
#include<iostream>
#include<cmath>
using namespace std;
int fl;
void prime(long int n)
{
long int i;
i=n-1;
while(i>=2)
{
if(n%i==0)
{
fl=1;
}
i–;
}
}
void rotate(long int a)
{
long int b,c,d,e,i,j,k,s,z,v,x[8],y[8],m;
b=a;
i=0;
while(b>0)
{
y[i]=b%10;
b=b/10;
i++;
}
c=0;
for(j=i-1;j>=0;j–)
{
x[c]=y[j];
c++;
}
m=i;
while(m>0)
{
c=m-1;
d=i-1;
e=0;
s=0;
while(e<i)
{
z=pow(10,d);
v=z*x[c%i];
c++;
d–;
e++;
s=s+v;
}
m–;
prime(s);
}
}
int main()
{
long int i=2,ct;
cout<<“\nEnter the Limit: “;
cin>>ct;
cout<<“\nCircular Prime Numbers less than “<<ct<<” : “;
while(i<=ct)
{
fl=0;
rotate(i);
if(fl==0)
{
cout<<“\n”<<i;
}
i++;
}
return 0;
}
Hope this is useful, thank you. You may like to read: How Prime Numbers & Encryption Are Related?,Encryption & Decryption For Kids, & From Transistors to CPU – Explained!