您的位置:首页 > 其它

PAT (Advanced Level)1015. Reversible Primes (20)

2018-02-27 21:36 477 查看
题目链接
//1015. Reversible Primes(20)

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int PimeJudge(int a) {
if (a < 2)
return 0;
if (a == 2 || a == 3)
return 1;
for (int i = 2; i*i <= a; i++) {
if (a%i == 0)
return 0;
}
return 1;
}

int main() {
int a, b;
while (cin >> a) {
if (a < 0)
return 0;
cin >> b;
int c[15];
int aa = a;
int sub = 0;
while (a != 0) {
c[sub++] = a % b;
a /= b;
}
int realinD = 0;
for (int i = 0; i < sub; i++) {
realinD += (c[i])*pow(b, sub - i - 1);
}
if (PimeJudge(aa) && PimeJudge(realinD))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: