P14339 [GeeksforGeeks] Even fibonacci numbers sum1455
普及-
题目描述

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).

Example 1:
Input:
N = 8
Output:
10
Explanation:
There are two even
fibonacci numbers less
than equal to 8, 8 and 2
and 8 + 2 = 10
Example 2:
Input:
N = 89
Output:
44
Explanation:
There are three even
fibonacci numbers less than
equal to 89, 8, 2 and 34
8 + 2 + 34 = 44
Your Task:
You don't need to read input or print anything. Your task is to complete the function evenFibSum() which takes an integer N as input parameters and returns the sum of all the Fibonacci number less than equal to N.

Expected Time Complexity: O(N)
Expected Space Complexity: O(1)

Constraints:
1 <= N <= 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 8
样例输出
10