I have a non linear recurrence relation a(n)=(n-1)*(a(n-1)+a(n-2)).How can I calculate a(n)%MOD in O(log(n)) time? Base conditions:-a(0)=0,a(1)=1
# | 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 | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
I have a non linear recurrence relation a(n)=(n-1)*(a(n-1)+a(n-2)).How can I calculate a(n)%MOD in O(log(n)) time? Base conditions:-a(0)=0,a(1)=1
Name |
---|
This is basically a recurrence for n!. (The base conditions are not mentioned but even with those, the solution will not be very different). And I dont think there is a simple way to do it in sub-linear time. :(
Actually, the base conditions matter a lot. For example, if a0 = 1, a1 = 0, then it's a recurrence for !n (number of derangements).
Xellos,since you are saying that base condition matters a lot,I take a(0)=1 and a(1)=0 .Can I calculate the recurrence relation in O(log(n))?
Maybe there's some obscure algorithm that does it, I don't know. But for the purpose of solving contest problems, assume you can't.
Sorry! By solution I meant "solving the task in logN time", because there is at least one base condition in which solution takes linear time. I guess I messed up with the wordings :P