Cody

Problem 232. Project Euler: Problem 2, Sum of even Fibonacci

Solution 2317888

Submitted on 21 May 2020 by Ramesh Kumar V
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x =4000000 y_correct = 4613732; assert(isequal(euler002(x),y_correct))

x = 4000000 y = 2 k = 0 a = 1 2 3 a = 1 2 3 5 a = 1 2 3 5 8 y = 10 k = 1 a = 1 2 3 5 8 13 a = 1 2 3 5 8 13 21 a = 1 2 3 5 8 13 21 34 y = 44 k = 2 a = 1 2 3 5 8 13 21 34 55 a = 1 2 3 5 8 13 21 34 55 89 a = 1 2 3 5 8 13 21 34 55 89 144 y = 188 k = 3 a = 1 2 3 5 8 13 21 34 55 89 144 233 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 798 k = 4 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 y = 3382 k = 5 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 y = 14328 k = 6 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 y = 60696 k = 7 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 y = 257114 k = 8 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 y = 1089154 k = 9 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 y = 4613732 k = 10 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 34 2178309 3524578 5702887 9227465 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 35 2178309 3524578 5702887 9227465 14930352

2   Pass
x =97455000 y_correct = 82790070; assert(isequal(euler002(x),y_correct))

x = 97455000 y = 2 k = 0 a = 1 2 3 a = 1 2 3 5 a = 1 2 3 5 8 y = 10 k = 1 a = 1 2 3 5 8 13 a = 1 2 3 5 8 13 21 a = 1 2 3 5 8 13 21 34 y = 44 k = 2 a = 1 2 3 5 8 13 21 34 55 a = 1 2 3 5 8 13 21 34 55 89 a = 1 2 3 5 8 13 21 34 55 89 144 y = 188 k = 3 a = 1 2 3 5 8 13 21 34 55 89 144 233 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 798 k = 4 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 y = 3382 k = 5 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 y = 14328 k = 6 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 y = 60696 k = 7 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 y = 257114 k = 8 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 y = 1089154 k = 9 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 y = 4613732 k = 10 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 34 2178309 3524578 5702887 9227465 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 35 2178309 3524578 5702887 9227465 14930352 y = 19544084 k = 11 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 36 2178309 3524578 5702887 9227465 14930352 24157817 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 37 2178309 3524578 5702887 9227465 14930352 24157817 39088169 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 ...

3   Pass
x =597455000 y_correct = 350704366; assert(isequal(euler002(x),y_correct))

x = 597455000 y = 2 k = 0 a = 1 2 3 a = 1 2 3 5 a = 1 2 3 5 8 y = 10 k = 1 a = 1 2 3 5 8 13 a = 1 2 3 5 8 13 21 a = 1 2 3 5 8 13 21 34 y = 44 k = 2 a = 1 2 3 5 8 13 21 34 55 a = 1 2 3 5 8 13 21 34 55 89 a = 1 2 3 5 8 13 21 34 55 89 144 y = 188 k = 3 a = 1 2 3 5 8 13 21 34 55 89 144 233 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 798 k = 4 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 y = 3382 k = 5 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 y = 14328 k = 6 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 y = 60696 k = 7 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 y = 257114 k = 8 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 y = 1089154 k = 9 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 y = 4613732 k = 10 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 34 2178309 3524578 5702887 9227465 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 35 2178309 3524578 5702887 9227465 14930352 y = 19544084 k = 11 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 36 2178309 3524578 5702887 9227465 14930352 24157817 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 37 2178309 3524578 5702887 9227465 14930352 24157817 39088169 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 ...

4   Pass
x =666576 y_correct = 257114; assert(isequal(euler002(x),y_correct))

x = 666576 y = 2 k = 0 a = 1 2 3 a = 1 2 3 5 a = 1 2 3 5 8 y = 10 k = 1 a = 1 2 3 5 8 13 a = 1 2 3 5 8 13 21 a = 1 2 3 5 8 13 21 34 y = 44 k = 2 a = 1 2 3 5 8 13 21 34 55 a = 1 2 3 5 8 13 21 34 55 89 a = 1 2 3 5 8 13 21 34 55 89 144 y = 188 k = 3 a = 1 2 3 5 8 13 21 34 55 89 144 233 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 798 k = 4 a = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 y = 3382 k = 5 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 y = 14328 k = 6 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 y = 60696 k = 7 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 y = 257114 k = 8 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 a = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040

Suggested Problems

More from this Author52

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!