We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This tutorial problem Tower 3-coloring is educational. www.afterdarkla.com We all know the importance of maths in our education system. All the doubts can be discussed here and hence can be solved. I loved the site very much.
M = 109+7.
To calculate (ab)%M and we know b can be very large(3N) .
Using Fermat's little theorem (a(M-1))%M = 1, first we will do b=b%(M-1) and then calculate (ab)%M by using fast exponentiation.
References :-
1. Codechef Discussion
2. Geeksforgeeks
No more comments
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
This tutorial problem Tower 3-coloring is educational. www.afterdarkla.com We all know the importance of maths in our education system. All the doubts can be discussed here and hence can be solved. I loved the site very much.
Hint:-
Here total number of possibilities are 3(3N).
M = 109+7.
To calculate (ab)%M and we know b can be very large(3N) .
Using Fermat's little theorem (a(M-1))%M = 1, first we will do b=b%(M-1) and then calculate (ab)%M by using fast exponentiation.
References :-
1. Codechef Discussion
2. Geeksforgeeks