| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 8229 |
| 문제명 | Fibonacci Representation |
| 레벨 | 플래티넘 4 |
| 분류 |
그리디 |
| 시간복잡도 | O(t*logn) |
| 인풋사이즈 | t<=10, n<=4*10^17 |
| 사용한 언어 | Python |
| 제출기록 | 30840KB / 68ms |
| 최고기록 | 60ms |
| 해결날짜 | 2022/04/28 |
"""Solution code for "BOJ 8229. Fibonacci Representation".
- Problem link: https://www.acmicpc.net/problem/8229
- Solution link: http://www.teferi.net/ps/problems/boj/8229
Tags: [Greedy]
"""
def main():
p = int(input())
for _ in range(p):
k = int(input())
answer = 0
while k:
a, b = 1, 1
while b <= k:
a, b = b, a + b
k = min(b - k, k - a)
answer += 1
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 8229. Fibonacci Representation".
- Problem link: https://www.acmicpc.net/problem/8229
- Solution link: http://www.teferi.net/ps/problems/boj/8229
Tags: [Greedy]
"""
def main():
p = int(input())
for _ in range(p):
k = int(input())
answer = 0
a, b = 1, 1
while b <= k:
a, b = b, a + b
while k:
while a > k:
a, b = b - a, a
k = min(b - k, k - a)
answer += 1
print(answer)
if __name__ == '__main__':
main()