Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- bool prime[1000005];
- bool visited[1000005];
- int main() {
- long long million = 1e6;
- for(int i = 0; i <= million; i++) {
- prime[i] = true;
- visited[i] = false;
- }
- prime[0] = false;
- prime[1] = false;
- for(long long i = 2; i <= million; i++) {
- if(prime[i]) {
- for(long long j = i * i; j <= million; j += i) {
- prime[j] = false;
- }
- }
- }
- string s;
- cin >> s;
- int primes = 0;
- for(int i = 0; i < (int) s.size(); i++) {
- string tmp = "";
- for(int j = i; j < i + 6 and j < (int) s.size(); j++) {
- tmp += s[j];
- int x = 0;
- for(int k = 0; k < (int) tmp.size(); k++) {
- x = (x * 10) + (tmp[k] - '0');
- }
- if(prime[x] and !visited[x]) {
- visited[x] = true;
- primes++;
- }
- }
- }
- cout << primes << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement