-
Notifications
You must be signed in to change notification settings - Fork 0
/
p35.cpp
46 lines (42 loc) · 858 Bytes
/
p35.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
#include <iostream>
#include <math.h>
using namespace std;
bool isPrime(int x)
{
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for(int i = 3; i <= sqrt(x); i+=2)
if (x%i==0)
return false;
return true;
}
bool rotate(int x)
{
int size = (int)log10(x);
int result = x;
for (int i = 0; i <= size; i++)
{
int digit = result % 10;
int rest = result / 10;
result = digit*(int)pow(10,size);
result += rest;
if (!isPrime(result))
return false;
}
return true;
}
int main(int argc, char **argv)
{
int count = 1;
for (int i = 3; i < 1000000; i += 2)
{
if (rotate(i))
{
count++;
}
}
cout << count << endl;
return 0;
}