fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool ispalindrome(long long int x)
  4. {
  5. long long int temp=x,rev=0;
  6. while(temp!=0)
  7. {
  8. rev=rev*10+temp%10;
  9. temp=temp/10;
  10. }
  11. if(rev==x)
  12. return 1;
  13. else
  14. return 0;
  15. }
  16.  
  17. bool isprime(long long int num)
  18. {
  19. int flag=0;
  20. for(int i=2;i<=sqrt(num);i++)
  21. {
  22. if(num%i==0)
  23. {
  24. flag=1;
  25. return 0;
  26. }
  27. }
  28. return 1;
  29. }
  30. int main() {
  31. // your code goes here
  32. long long int n;
  33. scanf("%lld",&n);
  34. for(long long int i=n;;i++)
  35. {
  36. if((isprime(i))&&(ispalindrome(i)))
  37. {
  38. cout<<i;
  39. exit(0);
  40. }
  41. }
  42. //cout<<n<<endl;
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 2732KB
stdin
1651565
stdout
1654561