언어, 알고리즘 공부/백준
[백준 알고리즘] 1193번 분수찾기(Python)
쿠몬e
2020. 3. 1. 22:05
<Python>
X = int(input())
num = 1
cnt = 0
while X > cnt:
cnt += num
num += 1
#while문을 빠져나온 뒤의 num은 분수의 분모 분자를 합한 값
if num % 2 == 0:
top = 1
bottom = num - 1
for i in range(cnt-X):
top += 1
bottom -= 1
else:
top = num-1
bottom = 1
for i in range(cnt-X):
top -= 1
bottom += 1
print(str(top)+"/"+str(bottom))
▼링크
반응형