Advertisement
Josif_tepe

Untitled

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