-
Notifications
You must be signed in to change notification settings - Fork 1
/
06219.cpp
47 lines (39 loc) · 766 Bytes
/
06219.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
#include <iostream>
#include <vector>
using namespace std;
vector<bool> prime(4000001, true);
void precompute(void) {
prime[0] = prime[1] = false;
for (int i=4; i<=4000000; i+=2) {
prime[i] = false;
}
for (int i=3; i*i<=4000000; i+=2) {
if (!prime[i]) continue;
for (int j=i*i; j<=4000000; j+=i*2) {
prime[j] = false;
}
}
}
int count(int n, int d) {
int cnt = 0;
while (n) {
if (n % 10 == d) cnt++;
n /= 10;
}
return cnt;
}
void solve(void) {
int a, b, d; cin >> a >> b >> d;
int ans = 0;
for (int i=a; i<=b; i++) {
if (prime[i] && count(i, d)) ans++;
}
cout << ans;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
precompute();
solve();
return 0;
}