-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1015.cpp
More file actions
51 lines (47 loc) · 967 Bytes
/
1015.cpp
File metadata and controls
51 lines (47 loc) · 967 Bytes
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
//
// 1015.cpp
// 算法
//
// Created by 王怡凡 on 2017/5/26.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<cmath>
bool isPrime(int n) {
if(n<=1) {
return false;
}
int sqr = (int)sqrt(n*1.0);
for(int i=2;i<=sqr;i++) {
if(n%i==0) {
return false;
}
}
return true;
}
int d[20];
int main() {
int n, radix;
while(scanf("%d",&n)!=EOF) {
if(n<0) break;
scanf("%d",&radix);
if(isPrime(n)==false) {
printf("No\n");
} else {
int len = 0;
do {
d[len++] = n % radix;
n /= radix;
} while(n!=0);
for(int i=0;i<len;i++) {
n = n*radix + d[i];
}
if(isPrime(n)==true) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
return 0;
}