Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 블록체인
- 액션바 필요없숴
- kotlin
- 10814
- 포너블
- 백준
- col -1 from CursorWindow
- 클라우드가 뭐야
- cmd2
- 코틀린
- pwnable
- UNIQUE constraint failed
- 파이썬
- 클라우드란?
- tlqkf
- Drive-By-Download
- java.lang.IllegalStateException
- Docker
- 6566
- pwnable.kr
- 나이순 정렬
- Couldn't read row 0
- cmd1
- 쏘큩
- python
- 애너그램 그룹
- 페니빙
- Make sure the Cursor is initialized correctly before accessing data for it.
- pwable.kr
- SQLiteConstraintException
Archives
- Today
- Total
푸르미르
[python]10870.피보나치 수 본문
주어진 n번째의 피보나치 수를 출력하는 문제이다.
피보나치 수는 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 ....이런식의 수열이다.
0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다.
n번째 피보나치 수는 (n-2)+(n-1)=n 이다.
이를 통해 코드를 짜보면,
1
2
3
4
5
6
7
8
9
10
|
def op(n):
if n==1 or n==2:
total=1
elif n==0:
total=0
else:
total=op(n-2)+op(n-1)
return total
print(op(int(input())))
|
cs |
'Baekjoon Online Judge' 카테고리의 다른 글
[python]2869.달팽이는 올라가고 싶다. (2) | 2021.01.10 |
---|---|
[python]1193.분수찾기 (0) | 2021.01.10 |
[python]10872.팩토리얼 (0) | 2021.01.07 |
[python]2292.벌집 (0) | 2021.01.07 |
[python]1316.그룹 단어 체커 (2) | 2021.01.06 |