Advertisement
ivnikkk

Untitled

Mar 22nd, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(l) cerr<<" bug : "<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(a) a.begin(), a.end()
  6. typedef long long ll;
  7. typedef long double ld;
  8.  
  9. // reshenie zdec
  10. ll dfs(ll n) {
  11.     if (n > 30) {
  12.         return n * n + 5 * n + 4;
  13.     }
  14.     if (n % 2 == 0) {
  15.         return dfs(n + 1) + 3 * dfs(n + 4);
  16.     }
  17.     else {
  18.         return 2 * dfs(n + 2) + dfs(n + 5);
  19.     }
  20. }
  21. signed main() {
  22.     ll ans = 0;
  23.     for (ll i = 1; i <= 1000; i++) {
  24.         ll cur = dfs(i);
  25.         string s = to_string(cur);
  26.         ll sum = 0;
  27.         for (ll j = 0; j < s.size(); j++) {
  28.             sum += s[j] - '0';
  29.         }
  30.         if (sum == 27) {
  31.             ans++;
  32.         }
  33.     }
  34.     cout << ans << '\n';
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement