how to solve linear recurrences of the type... f(n) = (n-1) * f(n-1) + (2*n-1) * f(n-2) with matrix exponentiation?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
how to solve linear recurrences of the type... f(n) = (n-1) * f(n-1) + (2*n-1) * f(n-2) with matrix exponentiation?
Name |
---|
This type of equations can't be solved with matrix exponentiation.
Question deleted.
If you consider a sequence f(0), f(1), f(2), .... You may get pair <f(i), f(i + 1)> from <f(i — 1), f(i)> by multiplying on matrix:
M(n) = { {0, 2n-1}, {1, n-1} }
Every multiplication depends on n. So you don't have a fixed matrix to power it. And it may appear impossible to get exact f(n).
But if you calculate modulo MOD. You will get repetition of matrix after MOD multiplications. So you may calculate product M(0) * M(1) * ... * M(MOD-1) = P. And then calculate final matrix as P^(n / MOD) * M(0) * M(1) ... M(n % MOD). The complexity will be O(MOD + log(n)).
If you use chinese theorem, you can calculate modulo several small numbers: MOD1, MOD2, ... MODk (where MODk is the maximal one). Then total Complexity will be O(log(n) + MODk + k^2).
You will get repetition of matrix after M multiplications
It seems that it must be
MOD
instead ofM
.Why? It looks like Fermat's little theorem for matrix. Is it correct?
Fixed.
I don't see any connection with the Fermat little theorem. Repetition will be, because if you calculate modulo MOD, then you may take reminder for any member of multiplication. It is easy to prove that: M(n) % MOD = M(n + MOD) % MOD. So when we calculate by modulo repetition will appear.