Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Reverse factorial
#include <iostream> #define MAXTAM 20 int MOD=1000000000+7; using namespace std; typedef long long ll; ll rev_fact[MAXTAM]; ll fact[MAXTAM]; ll fast_pow(ll x, ll y) { ll resp = 1, tmp = x; while(y) { if(y & 1) resp = (resp * tmp) % MOD; tmp = (tmp * tmp) % MOD; y >>= 1; } return resp; } void factorial() { fact[0] = 1; fact[1] = 1; fact[2] = 2; for(int i = 3; i <= MAXTAM+1; i++) { fact[i] =( i * fact[i-1])%MOD; //cout << i << ") " << fact[ i] << "\n"; } } int main() { int n, k; factorial(); rev_fact[MAXTAM-1] = (fast_pow(fact[MAXTAM], MOD-2)*MAXTAM)%MOD; //cout << fast_pow(fact[MAXTAM], MOD-2); for(int i = MAXTAM-2; i >= 0; i--) rev_fact[i] = ((i + 1) * rev_fact[i + 1]) % MOD; cin >> n; cin >> k; /*for(int i=1; i<MAXTAM; i++) cout << rev_fact[i] <<"\n";*/ cout << (fact[n]*((rev_fact[k]*rev_fact[n-k])%MOD))%MOD; // cout << fast_pow( 12, 8, 7); // cout << fact[4]; }
run
|
edit
|
history
|
help
0
ListTel
Rrrrrrrr
Sum of digits of number
II-32bit
GenericPacker
Good1
A+B ორობით სისტემაში
Microsoft - MaxEmployeeAttendence (R repititions - 1st step towards DP.)
СПКИ АП КЭП 3
Using c++11 range-base for loop