Pisano Period
Time limit1sMemory limit128 MB
The program finds the period length of Fibonacci remainders modulo M for each test case.
- Level
Easy3 of 10
- Topics
- Simulation, Math
- Solved
- No attempts yet
Problem
In 1960, Donald Wall, who worked at IBM, proved that the remainders of the Fibonacci numbers modulo form a repeating cycle.
For example, the first 10 Fibonacci numbers and their remainders modulo 11 are shown below.
The sequence of remainders repeats the same block over and over. Writing for the length of that repeating block, .
Wall proved several other properties.
- is even whenever .
- For every even integer greater than there is an with .
- when
Given , write a program that computes .
Input
The first line contains the number of test cases .
Each of the next lines contains two integers and separated by a single space. is the number of the test case and is the described above.
Output
For each test case, print the test case number and on one line, separated by a single space. Keep the order in which the test cases were given.
Constraints
- The sum of over all test cases is at most .