#P1306. GCD of Fibonacci Numbers

    ID: 14593 Type: Default 1000ms 256MiB

GCD of Fibonacci Numbers

GCD of Fibonacci Numbers

You are given two non-negative integers n and m. Consider the Fibonacci sequence defined by:

$$ f_i = \begin{cases} i & \text{if } i \le 1, \\ f_{i-1} + f_{i-2} & \text{if } i > 1, \end{cases}$$

Your task is to compute the greatest common divisor (GCD) of fn and fm, that is, $$\gcd(f_n, f_m)$$.

Hint: It is known that $$\gcd(f_n, f_m) = f_{\gcd(n, m)}.$$

inputFormat

The input consists of a single line containing two non-negative integers n and m separated by a space.

outputFormat

Output a single integer which is the value of $$\gcd(f_n, f_m)$$.

sample

1 1
1