Todos los desafíos
Fácil 0 resueltos 0% de aceptación

Sum Even Fibonacci Terms

Add the even Fibonacci terms that do not exceed a limit.

Begin the sequence with 1 and 2. Each following term is the sum of the previous two. Include only even-valued terms no greater than limit, then add them.

Implement even_fibonacci_sum(limit).

Input

limit: The largest term value that may be included.

Output

Return the sum, or 0 if there are no eligible terms.

Restricciones

0 ≤ limit ≤ 10¹⁵. The result fits a signed 64-bit integer.

Ejemplos

Ejemplo 1
Entrada:
limit = 50

Salida esperada:
expected = 44
Entrada:
long long limit = 50;

Salida esperada:
long long expected = 44;
Entrada:
long limit = 50;

Salida esperada:
long expected = 44;

Explicación

The even terms are 2, 8, and 34. Their sum is 44.

Ejemplo 2
Entrada:
limit = 1

Salida esperada:
expected = 0
Entrada:
long long limit = 1;

Salida esperada:
long long expected = 0;
Entrada:
long limit = 1;

Salida esperada:
long expected = 0;

Explicación

The first even term is 2, which exceeds the limit.

Referencias

Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.

Aprende de otros

Soluciones de la comunidad

Aún no hay soluciones publicadas. Resuelve este reto para compartir la primera.