| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 2373 |
| 문제명 | Fibonacci Game |
| 레벨 | 플래티넘 1 |
| 분류 |
게임 이론 |
| 시간복잡도 | O(logn) |
| 인풋사이즈 | n<=1,000,000 |
| 사용한 언어 | Python 3.11 |
| 제출기록 | 31256KB / 48ms |
| 최고기록 | 36ms |
| 해결날짜 | 2023/06/15 |
"""Solution code for "BOJ 2373. Fibonacci Game".
- Problem link: https://www.acmicpc.net/problem/2373
- Solution link: http://www.teferi.net/ps/problems/boj/2373
Tags: [game theory]
"""
def zeckendorf_representation(n):
ret = []
a, b = 1, 1
while b <= n:
a, b = b, a + b
while n:
while a > n:
a, b = b - a, a
n -= a
ret.append(a)
return ret
def main():
N = int(input())
zr = zeckendorf_representation(N)
print('-1' if len(zr) == 1 else zr[-1])
if __name__ == '__main__':
main()