Computer Science/알고리즘 ( Algorithm )
XX 알고리즘 문제 1
bugtype
2019. 3. 18. 16:56
fibo
예제)
Input: N = 12
Output: 10 // 0, 1, 2, 3, 5, 8 중 짝수인 2 + 8 = 10.
def solution(n):
if n < 2:
print "Error"
dp = [0,1]
ans = []
temp = 0
while temp < n:
temp = dp[0]+dp[1]
dp[0] = dp[1]
dp[1] = temp
if temp % 2 == 0:
ans.append(temp)
hab = sum(ans)
print(ans)
print(hab)
solution(12)
solution(30)
[2, 8]
10
[2, 8, 34]
44