728x90
9924번: The Euclidean Algorithm
The famous Euclidean algorithm is found in Book VII of the Elements. The Elements was written in 300 B.C.~by the Greek mathematician Euclid. It is rumored that King Ptolemy, having looked through the Elements, hopefully asked Euclid if there were not a sho
www.acmicpc.net
문제 풀이
A, B가 주어졌을 때, 특정한 계산을 통해 B가 0이 될 때 까지의 반복문 수행 횟수를 구해준다.
정답 코드
def solve(A, B, n) :
if B == 0 : return n - 1
return solve(B, A % B, n + A // B)
A, B = map(int, input().split())
print(solve(A, B, 0))
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 9950 - Rectangles [python] (0) | 2023.03.28 |
---|---|
[BOJ/백준] 9945 - Centroid of Point Masses [python] (0) | 2023.03.28 |
[BOJ/백준] 9907 - ID [python] (0) | 2023.03.28 |
[BOJ/백준] 9848 - Gift [python] (0) | 2023.03.28 |
[BOJ/백준] 9838 - XMAX [python] (0) | 2023.03.27 |