Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

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}

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?

Yes
GCD and Fibonacci Numbers

...