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

fast O(ln n) solution
Posted by Gleb Dubosarskii 22 Apr 2017 01:05
This problem can be solved in logarithmic time by using of such formula
|F_{n+1} F_n|  |k-1 1|^n  |k-1 1|
|           | =|     |  x |     |
|F_n F_{n-1}|  |k-1 0|    |1   0|
and applying fast multiplication. The answer is F_n. This formula generalize corresponding formula for Fibonacci sequence https://www.nayuki.io/page/fast-fibonacci-algorithms. It can be easily proven by induction.
Re: fast O(ln n) solution
Posted by webeseit 21 Nov 2018 23:37
but the formula is wrong when n=2

Edited by author 21.11.2018 23:38

Edited by author 21.11.2018 23:38