int64_t
gcdExtended(
constint64_t& a,
constint64_t& b, int64_t& x,
52int64_t x1 = 0, y1 = 0;
55x = y1 - (b / a) * x1;
66int64_t
modInverse(
constint64_t& a,
constint64_t& m) {
82 conststd::vector<int64_t>
94 autores = std::vector<int64_t>(max_arg_val + 1);
96 for(int64_t i = 1; i <= max_arg_val; i++) {
97res[i] = (res[i - 1] * i) % mod;
116int64_t
ncr(
constint64_t& n,
constint64_t& r)
const{
124 if(r == 0 || r == n) {
128 const autodenominator = (
fac[r] *
fac[n - r]) % p;
130 if(denominator_inv < 0) {
133 return(
fac[n] * denominator_inv) % p;
148 constint64_t expected;
150 TestCase(
constint64_t size,
constint64_t p,
constint64_t n,
151 constint64_t r,
constint64_t expected)
152: size(size), p(p), n(n), r(r), expected(expected) {}
154 conststd::vector<TestCase> test_cases = {
155 TestCase(60000, 1000000007, 52323, 26161, 224944353),
158 TestCase(1000, 13, 10, 3, 120 % 13),
164 for(
const auto& tc : test_cases) {
169std::cout <<
"\n\nAll tests have successfully passed!\n";
176 constint64_t size = 1e6 + 1;
177 constint64_t p = 1e9 + 7;
185 for(
inti = 0; i <= 7; i++) {
186std::cout << 6 <<
"C"<< i <<
" mod "<< p <<
" = "<< ncrObj.ncr(6, i)
Class which contains all methods required for calculating nCr mod p.
int64_t ncr(const int64_t &n, const int64_t &r) const
computes nCr % p
const std::vector< int64_t > fac
the p from (nCr % p)
NCRModuloP(const int64_t &size, const int64_t &p)
constructs an NCRModuloP object allowing to compute (nCr)p for inputs from 0 to size
static std::vector< int64_t > computeFactorialsMod(const int64_t &max_arg_val, const int64_t &mod)
stores precomputed factorial(i) % p value
int gcd(int num1, int num2)
int main()
Main function.
Functions for nCr modulo p implementation.
this namespace contains the definitions of the functions called from the class math::ncr_modulo_p::NC...
static void tests()
tests math::ncr_modulo_p::NCRModuloP
int64_t modInverse(const int64_t &a, const int64_t &m)
int64_t gcdExtended(const int64_t &a, const int64_t &b, int64_t &x, int64_t &y)
finds the values x and y such that a*x + b*y = gcd(a,b)
void example()
example showing the usage of the math::ncr_modulo_p::NCRModuloP class
represents single example inputs and expected output of the function longest_common_string_length
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4