Все задачи
Легко Решено: 0 Процент решений: 0%

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.

Ограничения

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

Примеры

Пример 1
Ввод:
limit = 50

Ожидаемый вывод:
expected = 44
Ввод:
long long limit = 50;

Ожидаемый вывод:
long long expected = 44;
Ввод:
long limit = 50;

Ожидаемый вывод:
long expected = 44;

Пояснение

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

Пример 2
Ввод:
limit = 1

Ожидаемый вывод:
expected = 0
Ввод:
long long limit = 1;

Ожидаемый вывод:
long long expected = 0;
Ввод:
long limit = 1;

Ожидаемый вывод:
long expected = 0;

Пояснение

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

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.