@@ -89,7 +89,7 @@ class NCRModuloP {
89
89
* @params[in] the numbers 'n', 'r' and 'p'
90
90
* @returns the value nCr % p
91
91
*/
92
- int64_t ncr (const uint64_t & n, const uint64_t & r, const uint64_t & p ) {
92
+ int64_t ncr (const uint64_t & n, const uint64_t & r) {
93
93
// Base cases
94
94
if (r > n) {
95
95
return 0 ;
@@ -121,13 +121,19 @@ class NCRModuloP {
121
121
* ncr function
122
122
* @returns void
123
123
*/
124
- static void tests (math::ncr_modulo_p::NCRModuloP ncrObj ) {
124
+ static void tests () {
125
125
// (52323 C 26161) % (1e9 + 7) = 224944353
126
- assert (ncrObj.ncr (52323 , 26161 , 1000000007 ) == 224944353 );
126
+ assert (
127
+ math::ncr_modulo_p::NCRModuloP (60000 , 1000000007 ).ncr (52323 , 26161 ) ==
128
+ 224944353 );
127
129
// 6 C 2 = 30, 30%5 = 0
128
- assert (ncrObj .ncr (6 , 2 , 5 ) == 0 );
130
+ assert (math::ncr_modulo_p::NCRModuloP ( 20 , 5 ) .ncr (6 , 2 ) == 0 );
129
131
// 7C3 = 35, 35 % 29 = 8
130
- assert (ncrObj.ncr (7 , 3 , 29 ) == 6 );
132
+ assert (math::ncr_modulo_p::NCRModuloP (100 , 29 ).ncr (7 , 3 ) == 6 );
133
+ }
134
+
135
+ void other_tests () {
136
+ assert (math::ncr_modulo_p::NCRModuloP (1000 , 13 ).ncr (10 , 3 ) == 120 % 13 );
131
137
}
132
138
133
139
/* *
@@ -142,9 +148,10 @@ int main() {
142
148
math::ncr_modulo_p::NCRModuloP (size, p);
143
149
// test 6Ci for i=0 to 7
144
150
for (int i = 0 ; i <= 7 ; i++) {
145
- std::cout << 6 << " C" << i << " = " << ncrObj.ncr (6 , i, p ) << " \n " ;
151
+ std::cout << 6 << " C" << i << " = " << ncrObj.ncr (6 , i) << " \n " ;
146
152
}
147
- tests (ncrObj); // execute the tests
153
+ tests (); // execute the tests
154
+ other_tests ();
148
155
std::cout << " Assertions passed\n " ;
149
156
return 0 ;
150
157
}
0 commit comments