GCD of Fibonacci Numbers
Time limit1sMemory limit256 MB
Compute the greatest common divisor of the Nth and Mth Fibonacci numbers and print it modulo 1000000007.
- Level
Medium5 of 10
- Topics
- Number theory, Math, Divide and conquer
- Solved
- No attempts yet
Problem
The Fibonacci sequence is defined by , , and for . It starts 0, 1, 1, 2, 3, 5, 8, 13, 21.
Solving the recurrence gives a closed form.
The sequence has many properties. Two of them are the following.
This problem asks for the greatest common divisor of two Fibonacci numbers. Given two integers and , compute . The value is huge, so print it modulo . Take the remainder after computing the greatest common divisor.
Input
The first line contains the number of test cases . ()
Each of the next lines contains two integers and separated by one space. ()
Output
For each test case, print modulo on its own line.