1.题目介绍
2.考察点,难度
进制转换,素数判定,难度易
3.解题代码
#include <cstdio>
#include <iostream>
using namespace std;
/*
判断素数函数
*/
bool isPrime(int n)
{
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++)
if ( n % i == 0) return false;
return true;
}
/*
进制转化函数
*/
int revD(int n, int D)
{
int n2D[20], num = 0, result = 0;
do {
n2D[num++] = n % D;
n = n / D;
} while(n > 0);
for (int i = 0; i < num; i++) result = result * D + n2D[i];
return result;
}
int main()
{
int n, D;
scanf("%d", &n);
while (n >= 0){
scanf("%d", &D);
printf("%s",isPrime(n) && isPrime(revD(n,D)) ? "Yes\n" : "No\n");
scanf("%d", &n);
}
return 0;
}
4.原题地址
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000