आसान 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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।