ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1013. K-based Numbers. Version 3

Solution with using matrix
Posted by __fractal 3 Dec 2019 10:17
Answer is number in the (1, 1) of this matrix
|k - 1  k - 1| ^ N
|  1     0   |
Example:
If n is 2 and k is 10 then
|9 9| ^ 2 = |90 81|
|1 0|       |9   9|
And answer is 90.
Use fast power algorithm to count it in O(logn).