素数打表,转置判断
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+10;
bool isprime[MAXN];
void init() {
memset(isprime, true, sizeof(isprime));
isprime[0] = isprime[1] = false;
for (int i = 2; i < MAXN; i++)
if (isprime[i])
for (int j = i<<1; j < MAXN; j += i)
isprime[j] = false;
}
int reverse(int x, int d) {
int a[30];
int cnt = 0;
while (x) {
a[cnt++] = x % d;
x /= d;
}
int ans = 0;
for (int i = 0; i < cnt; i++)
ans = ans * d + a[i];
return ans;
}
int main() {
init();
int n, d;
while (scanf("%d", &n), n >= 0) {
scanf("%d", &d);
if (isprime[n] && isprime[reverse(n, d)])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}