Fibonacci Sum of Large Numbers(Only Last Digit to be Printed)

后端 未结 5 1846
死守一世寂寞
死守一世寂寞 2020-12-31 12:44

I have been trying to come out with a solution regarding the problem of finding the last digit of the sum of large n Fibonacci series. I have been able to pass several test

5条回答
  •  有刺的猬
    2020-12-31 13:34

    If you only need to output the last digit as you said, I think you can just make use of the Pisano Period you mentioned, as for modular 10, the cycle length is only 60 and you can just pre-make an array of that 60 digits.

    If you want to compute by yourself, I think you can use Matrix Exponentiation which gives you O(lg N) complexity, when calculating the matrix exponents, keep storing the temporary result modular 10. See the Matrices section for your reference.

提交回复
热议问题