Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<bool> primes(1000000, true);
  6.  
  7. int power10(int a) {
  8. int arr[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
  9. return arr[a];
  10. }
  11.  
  12. void gen() {
  13. for (int i = 2; i < sqrt(1000000); ++i) {
  14. for (int j = i*i; j < 1000000; j += i) {
  15. primes[j] = false;
  16. }
  17. }
  18. }
  19.  
  20. int main()
  21. {
  22. ios::sync_with_stdio(0);
  23.  
  24. primes[1] = false;
  25. primes[0] = false;
  26. gen();
  27.  
  28. char c[1000000];
  29. cin >> c;
  30.  
  31. long long counter = 0;
  32. set<int> s;
  33. bool gottwo = false;
  34.  
  35. for (int i = 0; c[i] - '0' >= 0 && c[i] - '0' < 10; ++i) {
  36. int cur = c[i] - '0';
  37. if (cur == 2) {
  38. gottwo = true;
  39. continue;
  40. }
  41.  
  42. if (cur % 2 == 0 || cur == 0) continue;
  43.  
  44. if (cur != 1 && cur != 9)
  45. s.insert(cur);
  46.  
  47. // cout << "current : " << cur << endl;
  48.  
  49. for (int j = 1; j < 6; ++j) {
  50. if (i - j < 0) break;
  51.  
  52. cur += power10(j) * (c[i - j] - '0');
  53. // cout << "MOD current : " << cur << endl;
  54. // cout << "MOD current isPrime : " << primes[cur] << endl;
  55. if (primes[cur] == true) s.insert(cur);
  56. }
  57. }
  58.  
  59. for (set<int>::iterator si = s.begin(); si != s.end(); ++si) {
  60. counter++;
  61. }
  62.  
  63. cout << counter + (int)gottwo << endl;
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement