문제
- 백준 17626: Four Squares
- Silver V
- 문제링크
N = int(input())
min_sum = 4
for a in range(int(N**0.5), int((N//4)**0.5), -1):
if a*a == N:
min_sum = 1
break
else:
temp = N - a*a
for b in range(int(temp**0.5), int((temp//3)**0.5), -1):
if a*a + b*b == N:
min_sum = min(min_sum, 2)
continue
else:
temp = N - a*a - b*b
for c in range(int(temp**0.5), int((temp//2)**0.5), -1):
if n == a*a + b*b + c*c:
min_sum = min(min_sum, 3)
print(min_sum)
'개발공부 > algorithm' 카테고리의 다른 글
[leetcode][python] 278. First Bad Version - Binary Search (0) | 2021.07.04 |
---|---|
[Leetcode][python] 58: Length of Last Word (0) | 2021.06.24 |
[백준][Python] 2670: 연속부분 최대합 - DP (0) | 2021.06.06 |
[프로그래머스][python] 소수찾기 (0) | 2021.06.06 |
[프로그래머스][python] 크레인 인형 뽑기 - Stack (0) | 2021.05.24 |