#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
bool isPrime(int N)
{
if (N < 2)return false;
if (N == 2 || N == 3)return true;
for (int i =sqrt(N); i >=2; i--)
if (N%i == 0)return false;
return true;
}
int rev_num(int N, int D) //数字反转
{
int renum[15];
int i = 0;
while (N)
{
renum[i++] = N % D;
N /= D;
}
int sum = 0;
for (int j = 0; j < i; j++)
sum = sum*D + renum[j];
return sum;
}
int main()
{
int N, D;
cin >> N;
while (N >= 0)
{
cin >> D;
int n = rev_num(N, D);
if (isPrime(N)==true && isPrime(n)==true)
cout << "Yes" << endl;
else
cout << "No" << endl;
cin >> N;
}
return 0;
}
1015. Reversible Primes (20)
最新推荐文章于 2018-08-22 12:01:28 发布