Okay so the program is working, however I suppose it’s too slow for the submissions liking. What would you do to make it faster? Use a class, inline functions, etc.
int isPrime(long num);
int isPalindrome(unsigned long orig);
int main(int argc, const char * argv[])
{
int n = 0;
const int LIMIT = 1000000;
scanf("%d", &n);
int m = n;
while(n <= LIMIT) {
if(isPrime(m) && isPalindrome(m)){
printf("%d \n", m);
break;
}
else {
m++;
}
}
return 0;
}
int isPrime(long num)
{
if (num < 2)
return 0;
if (num > 2 && (num % 2) == 0)
return 0;
for(int i = 2; i < num; i++ )
{
if ( (num % i) == 0)
{
return 0;
}
}
return 1;
}
int isPalindrome(unsigned long orig)
{
unsigned long reversed = 0, n = orig;
while (n > 0)
{
reversed = reversed * 10 + n % 10;
n /= 10;
}
return orig == reversed;
}