题意:
给定一个十进制下的数n,然后在d进制下反转得到一个数
如果这两个数都是素数Yes,,否则No
思路:
如上
#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;
typedef long long ll;
const ll maxn = 1e8 + 7;
/*
分析:
23 @2
16 + 4 + 2 + 1 = 10111
11101 = 1 + 4 + 8 + 16= 29
*/
int n, d;
int R(int m) {
string s;
while(m) {
int t = m % d;
m /= d;
s.push_back((char)(t + '0'));
}
//cout << s << endl;
int res = 0;
for(int i = 0; i < s.size(); ++i) {
res = res * d + (int)(s[i] - '0');
}
return res;
}
bool P(int m) {
//cout << " *** " << m << endl;
if(m == 0 || m == 1) return false;
for(int i = 2; i*i <= m; ++i) {
if(m % i == 0) return false;
}
return true;
}
int main() {
n = d = -1;
while(scanf("%d%d", &n, &d) != EOF) {
if(d == -1) break;
if(P(n) && P(R(n))) {
puts("Yes");
}
else puts("No");
d = -1;
}
return 0;
}