Advertisement
pochti_da

Untitled

May 17th, 2021
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <functional>
  2. #include <cstdint>
  3.  
  4. void calc_binom(int n, int k, std::function<void (uint64_t)> cb) {
  5.     if (n > 0 && k > 0) {
  6.         try {
  7.             calc_binom(-n, -k, cb);
  8.         } catch (uint64_t res) {
  9.             cb(res);
  10.         }
  11.     } else {
  12.         int N = -n, K = -k;
  13.  
  14.         if (!N || !K || N == K) {
  15.             throw (uint64_t)1;
  16.         } else {
  17.             uint64_t t1, t2;
  18.  
  19.             try {
  20.                 calc_binom(n + 1, k, cb);
  21.             } catch (uint64_t res) {
  22.                 t1 = res;
  23.             }
  24.  
  25.             try {
  26.                 calc_binom(n + 1, k + 1, cb);
  27.             } catch (uint64_t res) {
  28.                 t2 = res;
  29.             }
  30.  
  31.             throw t1 + t2;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement