File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
project_euler/problem_137 Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Project Euler Problem 137: https://projecteuler.net/problem=137
3+
4+ Fibonacci Golden Nuggets
5+
6+ The polynomial sequence can be rewritten in the finite form:
7+
8+ A_F(x) = x / (1 - x - x^2)
9+
10+ And then the problem is to solve for it for rational x that give A_F(x) as positive
11+ integer. It turns out that the solution is for the n-th golden nugget is given by
12+ F(2n) * F(2n + 1), where F(k) is the k'th Fibonacci number.
13+
14+ Reference: https://oeis.org/A081018
15+
16+ """
17+
18+
19+ def solution (n : int = 15 ) -> int :
20+ """
21+ It calculates fibonachi numbers 2n and 2n+1, and returns their product.
22+
23+ >>> solution(3)
24+ 104
25+ >>> solution(10)
26+ 74049690
27+ """
28+
29+ k = 2 * n
30+
31+ fib1 = fib2 = 1
32+ for _ in range (k - 1 ):
33+ fib1 , fib2 = fib2 , fib1 + fib2
34+
35+ return fib1 * fib2
36+
37+
38+ if __name__ == "__main__" :
39+ print (f"{ solution () = } " )
You can’t perform that action at this time.
0 commit comments