[백준] 1193번 분수 찾기

거북이·2023년 3월 6일
0

백준[실버5]

목록 보기
98/114
post-thumbnail

💡문제접근

  • 처음에 규칙을 찾기가 어려웠는데 무작위로 이렇게 저렇게 작성하다보니 우연찮게 얻어 걸린 문제였다.

💡코드(메모리 : 31256KB, 시간 : 40ms)

import sys
input = sys.stdin.readline

X = int(input())

line = 0
max_num = 0
while X > max_num:
    line += 1
    max_num += line

diff = max_num - X
if line % 2 == 0:
    top = line - diff
    bottom = diff + 1
else:
    bottom = line - diff
    top = diff + 1
print(str(top) + "/" + str(bottom))

💡소요시간 : 21m

0개의 댓글