Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. vector <bool> prost(10000, 1);
  7. vector <bool> used(10001, 0);
  8. vector <bool> w(10001, 0);
  9.  
  10. void pr (int n) {
  11.         prost[0] = prost[1] = 0;
  12.         for (int i = 2; i < 10000; ++i) {
  13.             if (prost[i]) {
  14.                 for (int j = i * i; j < 10000; j += i) {
  15.                     prost[j] = 0;
  16.                 }
  17.             }
  18.         }
  19. }
  20.  
  21. bool a (int n) {
  22.     if (!n)
  23.         return 0;
  24.     if (used[n])
  25.         return w[n];
  26.     used[n] = 1;
  27.     bool q = 0, g;
  28.     for (int i = 1; i < 4; ++i) {
  29.         if (n < i || prost[n - i]) continue;
  30.         g = a(n - i);
  31.         if (!g)
  32.             q = 1;
  33.     }
  34.     w[n] = q;
  35.     return q;
  36. }
  37.  
  38. int main()
  39. {
  40. #ifndef ONLINE_JUDGE
  41.     freopen("input.txt", "r", stdin);
  42. #endif // ONLINE_JUDGE
  43.  
  44.     int n;
  45.     cin >> n;
  46.     pr(n);
  47.     if (a(n))
  48.     cout << 1;
  49.     else cout << 2;
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement