TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
This program aims at calculating nCr modulo p. More...
#include <cassert>
#include <iostream>
#include <vector>
Go to the source code of this file.
Classes | |
class | math::ncr_modulo_p::NCRModuloP |
Class which contains all methods required for calculating nCr mod p. More... | |
Namespaces | |
namespace | math |
for assert | |
namespace | ncr_modulo_p |
Functions for nCr modulo p implementation. | |
namespace | utils |
this namespace contains the definitions of the functions called from the class math::ncr_modulo_p::NCRModuloP | |
Functions | |
int64_t | math::ncr_modulo_p::utils::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) | |
int64_t | math::ncr_modulo_p::utils::modInverse (const int64_t &a, const int64_t &m) |
static void | tests () |
tests math::ncr_modulo_p::NCRModuloP | |
void | example () |
example showing the usage of the math::ncr_modulo_p::NCRModuloP class | |
int | main () |
This program aims at calculating nCr modulo p.
nCr is defined as n! / (r! * (n-r)!) where n! represents factorial of n. In many cases, the value of nCr is too large to fit in a 64 bit integer. Hence, in competitive programming, there are many problems or subproblems to compute nCr modulo p where p is a given number.
Definition in file ncr_modulo_p.cpp.
void example | ( | ) |
example showing the usage of the math::ncr_modulo_p::NCRModuloP class
Definition at line 175 of file ncr_modulo_p.cpp.
int64_t math::ncr_modulo_p::utils::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)
[in] | a | the first input of the gcd |
[in] | a | the second input of the gcd |
[out] | x | the Bézout coefficient of a |
[out] | y | the Bézout coefficient of b |
Definition at line 44 of file ncr_modulo_p.cpp.
int main | ( | void | ) |
Definition at line 191 of file ncr_modulo_p.cpp.
int64_t math::ncr_modulo_p::utils::modInverse | ( | const int64_t & | a, |
const int64_t & | m ) |
Find modular inverse of a modulo m i.e. a number x such that (a*x)m = 1
[in] | a | the number for which the modular inverse is queried |
[in] | m | the modulus |
Definition at line 66 of file ncr_modulo_p.cpp.
|
static |
tests math::ncr_modulo_p::NCRModuloP
Definition at line 142 of file ncr_modulo_p.cpp.