Skip to content

Commit e70791b

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank]: Project Euler #2: Even Fibonacci numbers. Documentation added.
1 parent ce45cf5 commit e70791b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @link Problem definition [[docs/hackerrank/projecteuler/euler002.md]]
2+
13
namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
24

35
using System.Diagnostics.CodeAnalysis;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# [Even Fibonacci numbers](https://www.hackerrank.com/contests/projecteuler/challenges/euler002)
2+
3+
- Difficulty: #easy
4+
- Category: #ProjectEuler+
5+
6+
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
7+
By starting with $ 1 $ and $ 2 $, the first $ 10 $ terms will be:
8+
9+
$$ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 $$
10+
11+
By considering the terms in the Fibonacci sequence whose values do not exceed
12+
$ N $, find the sum of the even-valued terms.
13+
14+
## Input Format
15+
16+
First line contains $ T $ that denotes the number of test cases. This is
17+
followed by $ T $ lines, each containing an integer, $ N $.
18+
19+
## Constraints
20+
21+
- $ 1 \leq T \leq 10^5 $
22+
- $ 10 \leq N \leq 4 × 10^{16} $
23+
24+
## Output Format
25+
26+
Print the required answer for each test case.
27+
28+
## Sample Input 0
29+
30+
```text
31+
2
32+
10
33+
100
34+
```
35+
36+
## Sample Output 0
37+
38+
```text
39+
10
40+
44
41+
```
42+
43+
## Explanation 0
44+
45+
- For $ N = 10 $, we have $ \{2, 8\} $, sum is $ 10 $.
46+
47+
- For $ N = 100 $, we have $ \{2, 8, 34 \} $, sum is $ 44 $.

0 commit comments

Comments
 (0)