This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ngthanhtrung23/ACM_Notebook_new
int factmod (int n, int p) { // n!, excluding p^k of course int res = 1; while (n > 1) { res = (res * ((n/p) % 2 ? p-1 : 1)) % p; for (int i=2; i<=n%p; ++i) res = (res * i) % p; n /= p; } return res % p; }
#line 1 "Math/NumberTheory/FactorialMod.h" int factmod (int n, int p) { // n!, excluding p^k of course int res = 1; while (n > 1) { res = (res * ((n/p) % 2 ? p-1 : 1)) % p; for (int i=2; i<=n%p; ++i) res = (res * i) % p; n /= p; } return res % p; }