Just learnt **Binary Matrix Exponentiation** for **Codeforces 166E** problem from:

Youtube: Gaurav Sen’s (gkcs) Matrix Exponentiation video

As there are a few blogs along with tutorial on codeforces itself for the problem, and some google results includes solutions as well. I have already read them but couldn’t understand the base cases and the matrix formation that we will be multiplying with itself to some power , then using DP and finally multiplying with base cases matrix to obtain actual solution.

Probably they weren’t beginners friendly or least I couldn’t understand any of them.

# I will be glad if someone help me out explaining his solution, or a brief description would be fine.

Link to problem:

Couldn’t think of any of the ways of solving **166E** as defined in tutorial except recursive tree traversal solution which exceeded time limit obviously: My solution: 32205350

Will be glad to be guided if needs to learn something else.

Thanks in advance.

@gkcs I’ll be glad if you help me