The number which is prime and also palindrome.

After many days of gap…  back to blogging…….

Q.) An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N, 1 ≤ N ≤ 1000000. You must find the smallest integer M ≥ N such that M is a prime number and M is a palindrome. For example, if N is 31 then the answer is 101.

Input format
A single integer N, (1 ≤ N ≤ 1000000), on a single line.
Output format
Your output must consist of a single integer, the smallest prime palindrome greater than or equal to N


void main()
   long int a;
   printf("Enter number: ");
   if(a <= 1000000)
     if(prime(a)) {printf("Number is: %d",a);getch();return;}
else printf("Plz enter number less than 1000000 next time");
int prime(long int a){
long int i;
for(i=2;i<=a/2;i++) if(a%i==0)return 0;

return 1;

int palindrome(long int a){
  long int temp=a,reverse=0;
 while( temp != 0 ){
  reverse = reverse * 10;
  reverse = reverse + temp%10;
  temp = temp/10;
  if(reverse == a) return 1;
  else return 0;

Shivaji varma… 😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s