103302: [Atcoder]ABC330 C - Minimize Abs 2
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:15
Solved:0
Description
Score : $300$ points
Problem Statement
You are given a positive integer $D$.
Find the minimum value of $|x^2+y^2-D|$ for non-negative integers $x$ and $y$.
Constraints
- $1\leq D \leq 2\times 10^{12}$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$D$
Output
Print the answer.
Sample Input 1
21
Sample Output 1
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 Input 2
998244353
Sample Output 2
0
Sample Input 3
264428617
Sample Output 3
32
Output
分数:300分
问题描述
给定一个正整数$D$。
求非负整数$x$和$y$的$|x^2+y^2-D|$的最小值。
限制条件
- $1\leq D \leq 2\times 10^{12}$
- 所有输入值都是整数。
输入
输入通过标准输入给出,格式如下:
$D$
输出
打印答案。
样例输入1
21
样例输出1
1
对于$x=4$和$y=2$,我们有$|x^2+y^2-D| = |16+4-21|=1$。
没有非负整数$x$和$y$使得$|x^2+y^2-D|=0$,所以答案是$1$。
样例输入2
998244353
样例输出2
0
样例输入3
264428617
样例输出3
32
HINT
已知D的值,求$|x^2+y^2-D|$的最小值是多少?其中x、y均是非负整数?