When to take modulo

I am confused in taking modulo in several questions. Generally it is %1000000007, but in some cases we take %1000000006 in between. When to take %1000000007 and %1000000006?

Can you give an example of where you’ve seen this?

line 48,71 in the above solution

1 Like

The reasons why it switches to module 10^9+6 are explained in the Editorial.


if u calculate ab %m then simple but if u wanna calculate a^b^c %m then we have to calculate res = bc %(m-1) then calculate ares %m

thank you!!!

1 Like