题目描述
Problem Description
Takahashi has $ n $ square tiles, each with a side length of $ 1 $ meter.
Takahashi wants to arrange some of these tiles without overlapping to form a large rectangle.
The resulting rectangle should be as close to a square as possible, but at the same time, he wants to minimize the number of leftover tiles.
What is the minimum sum of the absolute difference between the lengths of the sides of the rectangle and the number of leftover tiles?
Input Format
The input is given from the standard input in the following format:
$ n $
Output Format
Output the minimum value in one line.
Sample Input and Output
Sample Input #1
26
Sample Output #1
1
Sample Input #2
41
Sample Output #2
4
Sample Input #3
100000
Sample Output #3
37
Notes/Hints
Constraints
- $1 \leq n \leq 100,000$
Sample Explanation 1
Arranging the tiles to form a $5 \times 5$ square results in a difference of $ 0 $ between the lengths of the sides, and $ 1 $ leftover tile, making the sum $ 1 $. It is not possible to use all $ 26 $ tiles without leaving any leftover to form a square, so the answer is $ 1 $.
Sample Explanation 2
In this case, the optimal solution is to form a $5 \times 8$ rectangle with $ 1 $ leftover tile.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分