#C4654. GCD of Fibonacci Numbers
GCD of Fibonacci Numbers
GCD of Fibonacci Numbers
You are given two non-negative integers a and b. Your task is to compute the Fibonacci number corresponding to the greatest common divisor (GCD) of a and b. That is, you need to compute:
$$ Fib(\gcd(a, b)) $$
This is based on the property:
$$ \gcd(\text{Fib}(a), \text{Fib}(b)) = \text{Fib}(\gcd(a, b)) $$
where Fib(n)
denotes the nth Fibonacci number, defined as:
$$ Fib(0)=0, \quad Fib(1)=1, \quad Fib(n)=Fib(n-1)+Fib(n-2)\ \text{for}\ n\ge 2. $$
To efficiently compute the Fibonacci numbers for potentially large indices, you are encouraged to use matrix exponentiation.
inputFormat
The input consists of a single line containing two space-separated integers a and b (0 ≤ a, b ≤ 106). These represent the indices for which you need to compute the GCD Fibonacci number.
Note: The input is provided via standard input (stdin).
outputFormat
Output a single integer, which is the value of Fib(\gcd(a, b))
.
The output should be written to standard output (stdout).
## sample10 15
5