-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path35.cc
67 lines (62 loc) · 979 Bytes
/
35.cc
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <unordered_set>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
unordered_set<int> uPrimes;
vector<int> vPrimes = {2};
void genPrime(int);
bool isCircular(int);
int main(int argc, char const *argv[])
{
genPrime(1000000);
int circ = 0;
for(auto i : uPrimes){
if(isCircular(i))
circ++;
}
cout << circ << "\n";
return 0;
}
void genPrime(int max){
bool b;
for (int i = 2; i < max; i++){
b = true;
for (int j = 0; vPrimes[j] <= sqrt(i); j++){
if(i % vPrimes[j] == 0){
b = false;
break;
}
}
if(b){
vPrimes.push_back(i);
uPrimes.emplace(i);
}
}
}
int intLenght(int i){
int len = 0;
while(i){
i /= 10;
len++;
}
return len;
}
bool isCircular(int p){
int len = intLenght(p);
bool b = true;
int tmp;
for(int i = 1; i < len; i++){
tmp = p % 10;
p /= 10;
for(int j = 1; j < len; j++){
tmp *= 10;
}
p += tmp;
if(uPrimes.count(p) == 0){
b = false;
break;
}
}
return b;
}