파이썬 알고리즘
[파이썬] 백준 7113 Rectangle (while문)
뜻 지, 깨달음 오
2022. 10. 25. 17:13
https://gkim1011.tistory.com/54
[파이썬] 백준 7113 Rectangle
https://www.acmicpc.net/problem/7113 7113번: Rectangle Vilibald has decided to cut a right-angled checked page of size n×m cells into squares. First of all he cut off the largest possible square us..
gkim1011.tistory.com
정석으로 푸는건 재귀인데
recursionerror가 계속 생겨서 while문으로도 풀어보았다.
전체 코드)
n, m = map(int, input().split())
cnt = 0
while True:
if n>m:
n = n-m
cnt+=1
elif m>n:
m = m-n
cnt+=1
elif n==m:
cnt+=1
break
print(cnt)