Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Rev Fact 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]; } } void factorial_inv() { int x= fact[MAXTAM]; rev_fact[MAXTAM] = fast_pow(x, MOD-2, MOD); for(int i = MAXTAM-1; i >= 0; i--) rev_fact[i] = ((i + 1) * rev_fact[i + 1]) % MOD; } int main() { int n, k; factorial(); cout << "1)" << fact[20] << endl; factorial_inv(); factorial(); cin >> n; cin >> k; for(int i = MAXTAM-1; i >= 0; i--) cout << i << ")" << rev_fact[MAXTAM-3] << endl; //cout << fact[n]*rev_fact[k]*rev_fact[n-k]; // cout << fast_pow( 12, 8, 7); }
run
|
edit
|
history
|
help
0
Simple use of function templete and namespace
no copy elision
GenericPacker
Hangman
Test 1(2021)
memcpy
Test 2(2021)
Certificate Printing
mine
Dar