9128: ABC330 —— C - Minimize Abs 2
[Creator : ]
Description
You are given a positive integer $D$.
Find the minimum value of $|x^2+y^2-D|$ for non-negative integers $x$ and $y$.
Find the minimum value of $|x^2+y^2-D|$ for non-negative integers $x$ and $y$.
Input
The input is given from Standard Input in the following format:
```
$D$
```
```
$D$
```
Output
Print the answer.
Constraints
- $1\leq D \leq 2\times 10^{12}$
- All input values are integers.
- All input values are integers.
Sample 1 Input
21
Sample 1 Output
1
For x=4 and y=2, we have $∣x^2+y^2−D∣=∣16+4−21∣=1$.
There are no non-negative integers x and y such that $∣x^2+y^2−D∣=0$, so the answer is 1.
Sample 2 Input
998244353
Sample 2 Output
0
Sample 3 Input
264428617
Sample 3 Output
32
HINT
相同题目:ABC330。