Created
September 21, 2017 05:00
-
-
Save fazd/d50e451e09300abd567be93ae03f155f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string> | |
#include<vector> | |
#include<math.h> | |
using namespace std; | |
int contDig( int copia){ | |
int i=0; | |
while(copia!=0){ | |
i++; | |
copia=copia/10; | |
} | |
return i; | |
} | |
int voltear (int n) | |
{ | |
int i=contDig(n); | |
int total= (n%10)*pow(10,i-1); | |
n=n/10; | |
n=n+total; | |
return n; | |
} | |
int main () | |
{ | |
vector<bool> prime; | |
prime.push_back(false); | |
prime.push_back(false); | |
int n =100000000; | |
for(int i=2; i<=n; i++){ | |
prime.push_back(true); | |
} | |
for(int i=2; i*i<=n; i++){ | |
if(prime.at(i)){ | |
for(int j=2; j*i<=n; j++){ | |
prime.at(i*j)=false; | |
} | |
} | |
} | |
vector<int> an; | |
an.push_back(0); | |
an.push_back(0); | |
int cont=1; | |
for(int i=2; i<=n; i++){ | |
int num=voltear(i); | |
bool sw=true; | |
if(prime.at(i)){ | |
while(num!=i){ | |
if(prime.at(num)){ | |
num=voltear(num); | |
} | |
else{ | |
sw=false; | |
break; | |
} | |
} | |
if(sw){ | |
an.push_back(i); | |
cont++; | |
} | |
} | |
} | |
int k=1; | |
scanf("%d",&k); | |
while(k!=0){ | |
for(int i=1; i<=cont; i++){ | |
if(an.at(i)>k && an.at(i)<pow(10,contDig(k))){ | |
printf("%d\n",an.at(i)); | |
break; | |
} | |
else if (an.at(i)>pow(10,contDig(k))){ | |
printf("0\n"); | |
break; | |
} | |
} | |
scanf("%d",&k); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment