-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem35.cpp
85 lines (77 loc) · 1.56 KB
/
Problem35.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//55
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool flag[1000000];
bool isprime(ll num)
{
for(ll i = 2;i<=sqrt(num);i++)
{
if(num%i==0)
return false;
}
return true;
}
ll convert(string a)
{
ll val = 0;
for(int i=0;i<a.length();i++)
val = val*10 + a[i]-'0';
return val;
}
bool val(ll num)
{
ll arr[10];
int index = 0;
string a = to_string(num);
string in = a;
do
{
//rotate
//cout<<a<<" ";
char c = a[0];
for(int i=1;i<a.length();i++)
a[i-1] = a[i];
a[a.length()-1] = c;
//cout<<a<<" ";
ll n = convert(a);
//cout<<n<<"\n";
if(isprime(n)==false)
return false;
arr[index++] = n;
}while(a!=in);
for(int i=0;i<index;i++)
flag[arr[i]] = true;
return true;
}
int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll cnt = 13;
for(int i=0;i<1000000;i++)
flag[i] = false;
for(int i=101;i<1000000;i++)
{
if(flag[i])
{
cnt++;
continue;
}
if(isprime(i))
{
cout<<i<<"\n";
if(val(i))
{
flag[i] = true;
cnt++;
}
}
}
//cout<<val(197);
cout<<"\n"<<cnt<<"\n";
}