Geeksforgeeks

Error

×

You will be given two positive numbers **M** and **N**. Your task is to print the greatest common divisor of Fib(**M**) and Fib(**N**) where Fib(x) means the x'th Fibonacci numbers defined as:

Fib(0) = 0

Fib(1) = 1

for n > 1, Fib(n) = Fib(n-1) + Fib(n-2)

**Example 1:**

**Input:** M = 3, N = 6
**Output:** 2
**Explanation**: Fib(3) = 2 and Fib(6) = 8
So, GCD(2,8)%100 = 2

â€‹**Example 2:**

**Input**: M = 7, N = 8
**Output:** 1
**Explanation**: Fib(7) = 13 and Fib(8) = 21
So, GCD(13,21)%100 = 1

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **fibGcd()** which takes** M** and **N **as inputs and returns the answer.The answer may be very large, compute the answer modulo 100.

**Expected Time Complexity:** O(min(M, N))

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ M, N ≤ 10^{3}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

GCD and Fibonacci Numbers

...