Advertisement
Josif_tepe

Untitled

Mar 19th, 2024
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cstring>
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn = 1e6 + 10;
  9. bool is_prime[maxn];
  10. bool visited[maxn];
  11. int main() {
  12.     ios_base::sync_with_stdio(false);
  13.     memset(is_prime, true, sizeof is_prime);
  14.     memset(visited, false, sizeof visited);
  15.     is_prime[0] = false;
  16.     is_prime[1] = false;
  17.    
  18.     for(ll i = 2; i < maxn; i++) {
  19.         if(is_prime[i]) {
  20.             for(ll j = i * i; j < maxn; j += i) {
  21.                 is_prime[j] = false;
  22.             }
  23.         }
  24.     }
  25.     string s;
  26.     cin >> s;
  27.     ll res = 0;
  28.     for(int i = 0; i < s.size(); i++) {
  29.         int tmp = 0;
  30.         for(int j = i; j < min((int) s.size(), i + 7); j++) {
  31.             tmp = (tmp * 10) + (s[j] - '0');
  32.             if(tmp < 1000000 and is_prime[tmp] and !visited[tmp]) {
  33.                
  34.                 visited[tmp] = true;
  35.                 res++;
  36.             }
  37.         }
  38.     }
  39.     cout << res << endl;
  40.    
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement