PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000014. Tổng bình phương tối thiểu (Squares)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng bình phương tối thiểu (Squares)
Squares
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , a positive perfect square is an integer of the form for some positive integer , such as .
The same perfect square may be used more than once. Represent as a sum of positive perfect squares while minimizing the number of terms.
Input
The input contains one positive integer .
Output
Print one integer: the minimum number of positive perfect squares whose sum is .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
12
Output
3
Explanation
We have , using positive squares. It cannot be represented by one or two positive squares, so the answer is .