https://www.acmicpc.net/problem/1484
import sys
G = int(sys.stdin.readline().strip())
answers = []
low = 1
high = 2
while True:
diff = high*high - low*low
# (diff == G)이면 후보가 됨
if diff == G:
answers.append(high) # 현재 몸무게 = high
if diff >= G:
low += 1
else:
high += 1
if low >= high:
break
if high > 100000:
break
# 결과 출력
if not answers:
print(-1)
else:
# 오름차순 출력
for ans in sorted(answers):
print(ans)
'알고리즘 문제풀이' 카테고리의 다른 글
멀티탭 스케줄링 [백준 1700] (0) | 2025.03.08 |
---|---|
흙길 보수하기 [백준 1911] (0) | 2025.03.08 |
전쟁-전투[백준 1303] (0) | 2025.01.31 |
양치기 꿍[백준 3187] (0) | 2025.01.30 |
텔레포트 정거장[백준 18232] (0) | 2025.01.29 |