版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zero_1778393206/article/details/81396541
#include<iostream>
#include<cmath>
using namespace std;
int IsPrime(int a)
{
if (a == 1)
return 0; //1既不是质数也不是合数;
for (int i = 2; i <= sqrt(a); i++)
{
if (a%i == 0)
return 0;
}
return 1;
}
int main()
{
int n, d;
while (cin>>n && n > 0)
{
cin >> d;
if (IsPrime(n) == 1)
{
int a[10];
int i=0;
while (n)
{
a[i++] = n%d;
n = n / d;
}
int t = 0;
n = 0;
while (i--)
{
n = n*d + a[t++];
}
if (IsPrime(n) == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
else
cout << "No" << endl;
}
system("pause");
return 0;
}