The Very Greatest Common Divisor
Time limit2sMemory limit128 MB
Each input value is the determinant of a tridiagonal n by n matrix with 1 on the diagonal, 1 above, -1 below; find the gcd of two such determinants.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
Find the greatest common divisor of two integers and . Each of the numbers and is the determinant of a square matrix of the following form. It is a tridiagonal matrix whose main-diagonal entries are all , whose superdiagonal entries are all , whose subdiagonal entries are all , and all of whose other entries are .
Input
The first line contains the number of test cases (). Each test case consists of two lines: the first line contains an integer () and the second line contains an integer ().
Output
For each test case, print the greatest common divisor of and on its own line.