#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
#define INF 0x6fffffff
bool isPrime(int x) {
if (x < 2) return false;
if (x == 2|| x == 3) return true;
for (int i = 2; i <= sqrt(x); i++)
{
if (x%i==0)
return false;
}
return true;
}
int change(int x, int d)
{
int b[1000],n=0;
while (x > 0)
{
b[n++] = x%d;
x = x / d;
}
int sum=0;
int cou = n-1;
for (int i=0; i<n;i++)
{
sum += (pow(d,(cou--))*b[i]);
}
return sum;
}
int main()
{
int num, d;
while (cin >> num)
{
if (num < 0)break;
cin >> d;
if (isPrime(num))
{
num = change(num, d);
if (isPrime(num))
{
cout << "Yes" << endl;
}
else {
cout<< "No" << endl;
}
}
else {
cout << "No"<<endl;
}
}
return 0;
}
1015. Reversible Primes (20) 进制转换
最新推荐文章于 2019-10-31 10:31:41 发布