簡単 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用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。