ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 17626 |
문제명 | Four Squares |
레벨 | 실버 3 |
분류 |
정수론 |
시간복잡도 | O(sqrt(n)) |
인풋사이즈 | n<=50000 |
사용한 언어 | Python |
제출기록 | 31312KB / 84ms |
최고기록 | 36ms |
해결날짜 | 2021/08/14 |
"""Solution code for "BOJ 17626. Four Squares".
- Problem link: https://www.acmicpc.net/problem/17626
- Solution link: http://www.teferi.net/ps/problems/boj/17626
"""
import math
def main():
n = int(input())
squares = {i * i for i in range(1, math.isqrt(n) + 1)}
if n in squares:
print(1)
elif any(n - x in squares for x in squares):
print(2)
else:
while n % 4 == 0:
n //= 4
print(4 if n % 8 == 7 else 3)
if __name__ == '__main__':
main()