Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Factorial Inv wip
#include <iostream> #define MAXTAM 20 #define MOD 200 using namespace std; typedef long long ll; ll rev_fact[MAXTAM]; ll fact[MAXTAM]; ll fast_pow(ll x, ll y, int n) { ll resp = 1, tmp = x; while(y > 0) { if(y & 1) resp = (resp * tmp) % n; tmp = (tmp * tmp) % n; y >>= 1; } return resp; } void factorial() { fact[0] = 1; fact[1] = 1; for(int i = 2; i <= MAXTAM; i++) { fact[i] =( i * fact[i-1])%MOD; } } int main() { int n, k; factorial(); rev_fact[MAXTAM-1] = (fast_pow(fact[MAXTAM], MOD-2, MOD)*MAXTAM)%MOD; for(int i = MAXTAM-2; i >= 0; i--) rev_fact[i] = ((i + 1) * rev_fact[i + 1]) % MOD; cin >> n; cin >> k; cout << fact[n]*rev_fact[k]*rev_fact[n-k]; // cout << fast_pow( 12, 8, 7); }
run
|
edit
|
history
|
help
0
Dar
Problema2
10 wizards
code_chef
1744. Can You Eat Your Favorite Candy on Your Favorite Day?
Binary search2
GCC bug #79511
max subsequence of array
sysTest.cpp
Defining Class Members