Minimize Abs 2

AtCoder
IDabc330_c
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
21
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$.
Input #2
998244353
Output #2
0
Input #3
264428617
Output #3
32
API Response (JSON)
{
  "problem": {
    "name": "Minimize Abs 2",
    "description": {
      "content": "You are given a positive integer $D$. Find the minimum value of $|x^2+y^2-D|$ for non-negative integers $x$ and $y$.",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc330_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a positive integer $D$.\nFind the minimum value of $|x^2+y^2-D|$ for non-negative integers $x$ and $y$.\n\n## Constraints\n\n*   $1\\leq D \\leq 2\\times 10^{12}$\n*   All input values are intege...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments