Can nCr % x (n choose r modulo any value)
computed by matrix exponentiation? if yes, how?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
if n and k is less than 10^6, or mudule less than 10^6, you can precalc all factoials up to 10^6.
You can calculate Cnk in such a way for not prime modules too.
"You can calculate Cnk in such a way for not prime modules too." how can i calc it for not primes modules, since i am using euclids algorithm i cant get it right for not prime modules.
it's difficult to explain in a few words. look at the code
Your
ASS()
function introduces undefined behavior, which can be anything, including the program continuing without any failure or subtly subverting the output data. Why not just useassert()
from the standard library?Because it looks a way cooler that way.
this function introduces RE. assert() function will not work in release. can you offer me the right way?
Yes: the easiest way is to replace
++*(int*)0
withabort()
.If N is very large (10^100 for example), and R is reasonably small (100 for instance), you can create (R+1)x(R+1) matrix A, which has ones on the main diagonal and on the diagonal above main, than compute v(A^N), where v is [1,0,0,0,...,0]. Last element of resulting vector will be the answer.
I believe this is what you were looking for
Can you/someone here please provide a problem link that needs this technique so that I can try my solution on that?
Thanks in advance :-)