Project Euler
Project Euler #35 : Circular primes
jyheo98
2020. 8. 8. 13:15
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
|
vector<bool> isPrime(1000001);
bool solve(int n) {
set<int> a;
int digit = 0;
int temp = n;
while (temp > 0) {
digit++;
temp /= 10;
}
int pow = 1;
for (int i = 1; i < digit; i++) pow *= 10;
while (1) {
if (a.count(n)) return true;
a.insert(n);
if (isPrime[n] == 1) return false;
int nn = n % 10;
n /= 10;
n += nn * pow;
}
}
int main() {
isPrime[0] = isPrime[1]= 1;
for (int i = 2; i <= 1000000; i++) { if(isPrime[i] == 0)
for (int j = i * 2; j <= 1000000; j += i) {
isPrime[j] = 1;
}
}
int cnt = 0;
for (int i = 2; i <= 999999; i++) {
if (solve(i)) {
cnt++;
cout << i << " ";
}
}
cout << cnt;
}
|
cs |
Circular prime 으로는
2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311 9377 11939 19391 19937 37199 39119 71993 91193 93719 93911 99371 193939 199933 319993 331999 391939 393919 919393 933199 939193 939391 993319 999331
이 있다하오...