Advertisement
Josif_tepe

Untitled

Mar 20th, 2025
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. const ll maxn = 1e6 + 10;
  9.  
  10. int main() {
  11.     string s;
  12.     cin >> s;
  13.     int cnt=0;
  14.    
  15.     bool is_prime[maxn];
  16.        
  17.         memset(is_prime, true, sizeof is_prime);
  18.         is_prime[0] = false;
  19.         is_prime[1] = false;
  20.        
  21.        
  22.         for(ll i = 2; i <= maxn; i++) {
  23.             if(is_prime[i]) {
  24.                 for(ll j = i * i; j <= maxn; j += i) {
  25.                     is_prime[j] = false;
  26.                 }
  27.             }
  28.            
  29.         }
  30.     vector<bool>visited(1000000,false);
  31.     for(int i = 0; i < (int) s.size(); i++) {
  32.         string tmp = "";
  33.         for(int j = i; j < min((int) s.size(), i + 6); j++) {
  34.             tmp += s[j];
  35.             int string_to_int=0;
  36.             for(int k = 0;k<(int)tmp.size();k++){
  37.               string_to_int=string_to_int*10+(tmp[k]-'0');
  38.             }
  39.             bool dali_e_prost=true;
  40.            
  41.            
  42.             if(dali_e_prost==true && visited[string_to_int]==false && is_prime[string_to_int] == true){
  43.                 cnt++;
  44.                 visited[string_to_int]=true;
  45.             }
  46.         }
  47.     }
  48.     cout<<cnt<<endl;
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement