This Can't Go On Forever
Time limit1sMemory limit128 MB
For each modulus m up to 2^24, output the length of the Pisano period of the Fibonacci sequence modulo m.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Long ago, in a galaxy far, far away, there was a world whose favorite pet — the taye — reproduced by budding. Once a young taye separated from its parent, it needed exactly one unit of time to mature, which is also exactly how long a fresh bud takes to grow and separate from its parent. Tayes live practically forever, so their owners like to count how many they will eventually have. Suppose that at time you own no taye, and at time a friend gives you a single freshly budded (still immature) taye.
The number of tayes you own then follows the recurrence
These are the Fibonacci numbers. If the recurrence is computed under a fixed modulus (every value taken modulo ), the sequence of remainders eventually starts repeating. The question is: how long is one full period before it repeats?
The first few sequences look like this:
For each modulus given in the input, determine the length of the smallest period of this sequence and report it.
Input
The input contains an unknown number of lines. Each line holds a single integer with (that is, ). The final line contains , which marks the end of the input and must not be processed.
Output
For each modulus in the input, print the modulus, a single space, and then the length of the smallest period of the Fibonacci sequence taken modulo .