Tag Archives: Fibonacci

Even Fibonacci Numbers Sum

Given a limit, find the sum of all the even-valued terms in the Fibonacci sequence below given limit. The first few terms of Fibonacci Numbers are, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 ,… (Even numbers are highlighted). Examples: Input : limit = 8 Output : 10 Explanation :… Read More »

Nth Even Fibonacci Number

Given a value n, find the n’th even Fibonacci Number. Input : n = 3 Output : 34 Input : n = 4 Output : 144 Input : n = 7 Output : 10946 The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,… Read More »

GCD and Fibonacci Numbers

You are given two positive numbers M and N. The task is to print greatest common divisor of M’th and N’th Fibonacci Numbers. The first few Fibonacci Numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …. Note that 0 is considered as 0’th Fibonacci Number. Examples: Input :… Read More »

Non Fibonacci Numbers

Given a positive integer n, the task is to print the n’th non Fibonacci number. The Fibonacci numbers are defined as: Fib(0) = 0 Fib(1) = 1 for n >1, Fib(n) = Fib(n-1) + Fib(n-2) First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 141, …….. Examples:… Read More »

Sum of Fibonacci Numbers

Given a number positive number n, find value of f0 + f1 + f2 + …. + fn where fi indicates i’th Fibonacci number. Remember that f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, … Input : n = 3 Output : 4 Explanation :… Read More »

Matrix Exponentiation

This is one of the most used techniques in competitive programming. Let us first consider below simple question. What is the minimum time complexity to find n’th Fibonacci Number? We can find n’th Fibonacci Number in O(Log n) time using Matrix Exponentiation. Refer method 4 of this for details. In this post, a general implementation… Read More »