Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Blasius
- projecteuler
- 파이썬
- 예제
- FTCS
- 통계학
- Fluid Dynamics
- Statistics
- Turbulent
- Compressible Flow
- regression
- programmers
- 회귀
- Python
- Finite Difference Method
- 우선순위큐
- heap
- Laminar
- 프로그래머스
- Boundary Layers
- Fluids
- Heat Equation
- 힙
- Navier-Stokes
- Crank-Nicolson
- 유체역학
- python3
- 이중우선순위큐
- 디스크 컨트롤러
- 프로젝트오일러
Archives
- Today
- Total
Sudal's Garage
Project Euler 2 본문
Question:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
문제:
피보나치 수열의 각 항은 바로 앞의 항 두 개를 더한 것이 됩니다. 1과 2로 시작하는 경우 이 수열은 아래와 같습니다.
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
짝수이면서 4백만 이하인 모든 항을 더하면 얼마가 됩니까?
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 | Fibonacci = [1,2] even_sum = 2 for i in range(2,int(4e4)): Fibonacci.append(Fibonacci[i - 2] + Fibonacci[i - 1]) if Fibonacci[i] > int(4e6): break if Fibonacci[i] % 2 == 0: even_sum += Fibonacci[i] print(even_sum) | cs |
피보나치 수열의 첫 두항을 만들고,
수열의 특정항이 4백만 초과 일 때 break.
'Programming > Project Euler - python' 카테고리의 다른 글
Project Euler 5 (0) | 2019.01.30 |
---|---|
Project Euler 4 (0) | 2019.01.30 |
Project Euler 3 (0) | 2019.01.30 |
Project Euler 1 (0) | 2019.01.30 |
Project Euler (0) | 2019.01.30 |