mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Added an O(1) solution to problem 002 (#776)
* Added an O(1) solution to problem 002 * Removed comments from sol3.py that were accidentally added to sol4.py
This commit is contained in:
parent
06dbef04a0
commit
7b89d03dd7
13
project_euler/problem_02/sol4.py
Normal file
13
project_euler/problem_02/sol4.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import math
|
||||
from decimal import *
|
||||
|
||||
getcontext().prec = 100
|
||||
phi = (Decimal(5) ** Decimal(0.5) + 1) / Decimal(2)
|
||||
|
||||
n = Decimal(int(input()) - 1)
|
||||
|
||||
index = (math.floor(math.log(n * (phi + 2), phi) - 1) // 3) * 3 + 2
|
||||
num = round(phi ** Decimal(index + 1)) / (phi + 2)
|
||||
sum = num // 2
|
||||
|
||||
print(int(sum))
|
Loading…
Reference in New Issue
Block a user