Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<bool> primes(1000000, true);
- int power10(int a) {
- int arr[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
- return arr[a];
- }
- void gen() {
- for (int i = 2; i < sqrt(1000000); ++i) {
- for (int j = i*i; j < 1000000; j += i) {
- primes[j] = false;
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- primes[1] = false;
- primes[0] = false;
- gen();
- char c[1000000];
- cin >> c;
- long long counter = 0;
- set<int> s;
- bool gottwo = false;
- for (int i = 0; c[i] - '0' >= 0 && c[i] - '0' < 10; ++i) {
- int cur = c[i] - '0';
- if (cur == 2) {
- gottwo = true;
- continue;
- }
- if (cur % 2 == 0 || cur == 0) continue;
- if (cur != 1 && cur != 9)
- s.insert(cur);
- // cout << "current : " << cur << endl;
- for (int j = 1; j < 6; ++j) {
- if (i - j < 0) break;
- cur += power10(j) * (c[i - j] - '0');
- // cout << "MOD current : " << cur << endl;
- // cout << "MOD current isPrime : " << primes[cur] << endl;
- if (primes[cur] == true) s.insert(cur);
- }
- }
- for (set<int>::iterator si = s.begin(); si != s.end(); ++si) {
- counter++;
- }
- cout << counter + (int)gottwo << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement