#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
bool is_prime(int x)
{
if (x <= 1)
return false;
for (int i = 2; i * i <= x; i++)
{
if (x % i == 0)
return false;
}
return true;
}
int main()
{
int x, y;
int flag = 0;
while (cin >> x && x >= 0)
{
if (flag)
puts("");
flag++;
cin >> y;
int n = x;
int len = 0, a[100000] ;
do
{
a[len++] = n % y;
n /= y;
} while (n);
for (int i = 0; i < len; i++)
{
n = n * y + a[i];
}
if (is_prime(n) && is_prime(x))
cout << "Yes";
else
cout << "No";
}
}
solution#include <iostream>#include <cmath>#include <cstring>using namespace std;bool is_prime(int x){ if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return