1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <iostream> #include <stdio.h> #include <vector> using namespace std; int prime[1000001]; vector<int> v; int palin(int a) { if(a<=11) return 1; int org=a; int r=0; while(a) { r*=10; r+=(a%10); a/=10; } if(r==org) return 1; return 0; } int main() { for(int j=1;j<1000001;j++) prime[j]=0; for(int i=2;i<1000001/2;i++) { if(prime[i]==0) for(int j=i+i;j<1000001;j+=i) prime[j]=1; } for(int i=1;i<1000001;i++) { if(prime[i]==0) { if(palin(i)) //cout<<i<<"\n"; //v.push_back(i); prime[i]=-3; } } //cout<<v.size()<<"\n"; int n; while(cin>>n) { cout<<2*n<<"\n"; if(prime[n]==-3) break; } return 0; } |