Hi, hope you all have a good day (or a good night, it's midnight in my area lol). Recently I came across a problem, which takes two integers — n and m — as input, with 3 <= n, m <= 10^9
. The problem asks for the value of F(F(i)) mod m
, with F(i)
denoting the i
-th Fibonacci number. I'm not sure if this question has been asked before on any platform (though I'm pretty sure no one has asked about it on English Competitive Programming Forums), but this seems to be a direct application of the Pisano Period. However, I am only able to find an O(m^{2})
algorithm, which does not suffice the condition of this problem. Even though there seems to be a fast enough algorithm on mathoverflow, there said that this algorithm may fail with specific prime numbers. So, my question is does there exist a precise method of calculating the pisano period of large number >= 10^9
? Thanks in advance for your responses, I will really appreciate your helps.