Advertisement
egormerk

rege

Mar 9th, 2021
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. bool f19 (int s, int p) {
  7.     if (s >= 36 && p == 2) {
  8.         return true;
  9.     } else {
  10.         if (s < 36 && p == 2) return false;
  11.         if (s >= 36) return false;
  12.     }
  13.     return f19(s + 1, p + 1) || f19(s + 2, p + 1) || f19(s * 2, p + 1);
  14. }
  15.  
  16. bool f20 (int s, int p) {
  17.     if (s >= 36 && p == 3) {
  18.         return true;
  19.     } else {
  20.         if (s < 36 && p == 3) return false;
  21.         if (s >= 36) return false;
  22.     }
  23.     if (p % 2 != 0) return f20(s + 1, p + 1) && f20(s + 2, p + 1) && f20(s * 2, p + 1);
  24.     return f20(s + 1, p + 1) || f20(s + 2, p + 1) || f20(s * 2, p + 1);
  25. }
  26.  
  27. bool f21 (int s, int p) {
  28.     if (s >= 36 && (p == 4 || p == 2)) {
  29.         return true;
  30.     } else {
  31.         if (s < 36 && p == 4) return false;
  32.         if (s >= 36) return false;
  33.     }
  34.     if (p % 2 == 0) return f21(s + 1, p + 1) && f21(s + 2, p + 1) && f21(s * 2, p + 1);
  35.     return f21(s + 1, p + 1) || f21(s + 2, p + 1) || f21(s * 2, p + 1);
  36. }
  37.  
  38. bool f21d (int s, int p) {
  39.     if (s >= 36 && p == 2) {
  40.         return true;
  41.     } else {
  42.         if (s < 36 && p == 2) return false;
  43.         if (s >= 36) return false;
  44.     }
  45.     if (p % 2 == 0) return f21d(s + 1, p + 1) && f21d(s + 2, p + 1) && f21d(s * 2, p + 1);
  46.     return f21d(s + 1, p + 1) || f21d(s + 2, p + 1) || f21d(s * 2, p + 1);
  47. }
  48.  
  49. int main() {
  50.     cout << "19: ";
  51.     for (int i = 1; i <= 35; i++) {
  52.         if (f19(i, 0)) {
  53.             cout << i << endl;
  54.             break;
  55.         }
  56.     }
  57.     cout << "20: ";
  58.     for (int i = 1; i <= 35; i++) {
  59.         if (f20(i, 0)) {
  60.             cout << i << " ";
  61.         }
  62.     }
  63.     cout << endl << "21: ";
  64.     for (int i = 1; i <= 35; i++) {
  65.         if (f21(i, 0)) {
  66.             cout << i << " ";
  67.         }
  68.     }
  69.     cout << endl << "No 21: ";
  70.     for (int i = 1; i <= 35; i++) {
  71.         if (f21d(i, 0)) {
  72.             cout << i << " ";
  73.         }
  74.     }
  75. }
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement