Even Fibonacci Numbers Sum
Submissions: 4108   Accuracy:

21.57%

  Difficulty: Easy   Marks: 2

Given a number N find the sum of all the even valued terms in the fibonacci sequence less than or equal to N.
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).

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains the integer N.

Output:
Print the sum of all the even valued terms in the fibonacci sequence less than or equal to given N. Print the answer for each test case in a new line.

Constraints:
1<= T <=100

1<= N <=1000000

Example:
Input:

2
8
400

Output:
10

188

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra
Author: sujnesh


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.