-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1015.cpp
54 lines (48 loc) · 841 Bytes
/
1015.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cstdio>
#include <stdlib.h>
#include <cmath>
using namespace std;
bool isprime(int num) {
int i;
int sq;
if (num > 1) {
sq = (int)sqrt((double)num);
for ( i = 2; i <= sq; i++) {
if (num % i == 0)break;
}
if (i > sq)return 1;
}
return 0;
}
int reverse(int num, int radix) {
int re_num = 0;
while (num > 0) {
re_num = re_num*radix + num%radix;
num = num / radix;
}
return re_num;
}
int main() {
int prime, radix;
int num;
scanf_s("%d", &num);
while (num > 0) {
prime = num;
scanf_s("%d", &radix);
if (isprime(prime)) {
num = reverse(prime, radix);
if (isprime(num)) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
else {
printf("No\n");
}
scanf_s("%d", &num);
}
system("pause");
return 0;
}