daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream in("nmult.in");
  6. ofstream out("nmult.out");
  7.  
  8. const int MOD = 666013;
  9.  
  10. long long putere(long long x, int p) {
  11.     long long a = 1;
  12.     x %= MOD;
  13.     while(p > 0) {
  14.         while(p % 2 == 0) {
  15.             x = x * x % MOD;
  16.             p /= 2;
  17.         }
  18.         a = a * x % MOD;
  19.         p--;
  20.     }
  21.     return a;
  22. }
  23.  
  24. void genComb(int n, int k) {
  25.     if(k > n-k) k = n-k;
  26.     long long c = 1, f = 1;
  27.     for(int i = 1; i <= k; i++) {
  28.         c = c*(n-i+1)%MOD;
  29.         f = f*i%MOD;
  30.     };
  31.     c = c * putere(f, MOD-2) % MOD;
  32.     out << c;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.     int k, n, w;
  39.     in >> n >> k >> w;
  40.     int r = n - (k + (k-1)*(w-1));
  41.     if(r < 0) out << 0 << '\n';
  42.     else if(r == 0) out << 1 << '\n';
  43.     else genComb(r+k, r);
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top