#abc330c. C - Minimize Abs 2

C - Minimize Abs 2

Score : 300300 points

问题描述

给定一个正整数 DD

求非负整数 xxyy 使得 x2+y2D|x^2+y^2-D| 的最小值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a positive integer DD.

Find the minimum value of x2+y2D|x^2+y^2-D| for non-negative integers xx and yy.

Constraints

  • 1D2×10121\leq D \leq 2\times 10^{12}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

DD

Output

Print the answer.

Sample Input 1

21

Sample Output 1

1

For x=4x=4 and y=2y=2, we have x2+y2D=16+421=1|x^2+y^2-D| = |16+4-21|=1.

There are no non-negative integers xx and yy such that x2+y2D=0|x^2+y^2-D|=0, so the answer is 11.

Sample Input 2

998244353

Sample Output 2

0

Sample Input 3

264428617

Sample Output 3

32

update @ 2024/3/10 01:13:40