#P4994. 终于结束的起点
终于结束的起点
Description
The well-known Fibonacci sequence is computed as follows.
$$\mathrm{fib}(n)=\begin{cases} 0,& n=0 \\ 1,& n=1 \\ \mathrm{fib}(n-1) + \mathrm{fib}(n-2),& n>1 \end{cases}$$That is, , where each term is the sum of the previous two terms.
Little F discovered that if we take every term of the Fibonacci sequence modulo any positive integer greater than , the sequence will always become periodic.
Of course, Little F soon understood why: () and () have at most possible pairs of values, so a cycle must appear within steps.
Even more generally, we can prove that no matter what modulus we choose, the Fibonacci sequence modulo will eventually look like .
Now, given a modulus , please find the smallest such that and .
Input Format
Input one line containing a positive integer .
Output Format
Output one line containing a positive integer .
2
3
6
24
Hint
Explanation for Sample 1
The Fibonacci sequence is . After taking modulo , it becomes .
We can see that when , and , which is exactly what we need, and it is the smallest such .
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
Notes
If you still do not know what modulo means, I would be happy to tell you. Modulo means taking the remainder of integer division, that is, the part that “cannot be divided evenly” at the end of long division. In other words,
$$a \bmod M =k \iff a = bM + k\ (M > 0, 0 \leq k < M)$$where , , and are all non-negative integers.
If you use C / C++, you can use % for modulo.
If you use Pascal, you can use mod for modulo.
Translated by ChatGPT 5
京公网安备 11011102002149号