-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler037.cpp
62 lines (57 loc) · 1.13 KB
/
Euler037.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define llu unsigned long long int
#define lim 1000050
bool b[lim]={0};
int ten[8]={1,10,100,1000,10000,100000,1000000,10000000};
int fun(int n)
{
int m=n;int c=0;
while(m)
{
if(b[m])
return 0;
m/=10;c++;
}//cout<<"R";
while(c>1)
{
n=n%(ten[--c]);//cout<<b[n]<<endl;
if(b[n])
return 0;
}//cout<<"Y\n";
return 1;
}
int main() {
b[0]=b[1]=1;
for(int i=4;i<lim;i+=2)
b[i]=1;
for(int i=3;i*i<=lim;i++)
{
if(!b[i])
{
for(int j=i*i;j<lim;j+=i)
b[j]=1;
}
}//cout<<b[3797]<<b[797]<<b[97]<<b[7];
llu n;
cin>>n;
int c=0;
llu ans=0;
for(int i=10;i<n;i++)
{
if(fun(i))
{
//cout<<i<<" ";
ans+=i;c++;
}
if(c==11)
break;
}
cout<<ans;
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}