I have worked up a solution for Prime Palindromes, and after a lot of debugging, the code started being successful with the sample input and I thought i should submit this, but doing so, it gives me wrong answer!
Can anyone help me figure out my mistakes ?
#include <stdio.h>
#include <stdlib.h>
int isPalindrome(int x) {
int div = 1;
while (x / div >= 10) {
div *= 10;
}
while (x != 0) {
int l = x / div;
int r = x % 10;
if (l != r)
return 1;
x = (x % div) / 10;
div /= 100;
}
return 0;
}
int main(void)
{
int n;
scanf ("%d\n", &n);
int i,j, sum = 0;
int from = n;
int to = 1000000;
int *sieve=(int *)calloc(to+1,sizeof(int));
for(i=2;i<=to;i++)
{
if(sieve[i]==0)
{
if(i>=from)
{
if (isPalindrome(i) == 0)
{
printf ("%d\n", i);
return 0;
}
}
if(i*i<=to)
{
for(j=i;j<=to;j+=i)
{
sieve[j]=1;
}
}
}
}
free(sieve);
}