Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e6 + 10;
- bool is_prime[maxn];
- bool visited[maxn];
- int main() {
- ios_base::sync_with_stdio(false);
- memset(is_prime, true, sizeof is_prime);
- memset(visited, false, sizeof visited);
- is_prime[0] = false;
- is_prime[1] = false;
- for(ll i = 2; i < maxn; i++) {
- if(is_prime[i]) {
- for(ll j = i * i; j < maxn; j += i) {
- is_prime[j] = false;
- }
- }
- }
- string s;
- cin >> s;
- ll res = 0;
- for(int i = 0; i < s.size(); i++) {
- int tmp = 0;
- for(int j = i; j < min((int) s.size(), i + 7); j++) {
- tmp = (tmp * 10) + (s[j] - '0');
- if(tmp < 1000000 and is_prime[tmp] and !visited[tmp]) {
- visited[tmp] = true;
- res++;
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement