Square Constraints

AtCoder
IDagc036_f
Time4000ms
Memory256MB
Difficulty
Given is an integer $N$. How many permutations $(P_0,P_1,\cdots,P_{2N-1})$ of $(0,1,\cdots,2N-1)$ satisfy the following condition? * For each $i$ $(0 \leq i \leq 2N-1)$, $N^2 \leq i^2+P_i^2 \leq (2N)^2$ holds. Since the number can be enormous, compute it modulo $M$. ## Constraints * $1 \leq N \leq 250$ * $2 \leq M \leq 10^9$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $M$ [samples]
Samples
Input #1
2 998244353
Output #1
4

Four permutations satisfy the condition:

*   $(2,3,0,1)$
*   $(2,3,1,0)$
*   $(3,2,0,1)$
*   $(3,2,1,0)$
Input #2
10 998244353
Output #2
53999264
Input #3
200 998244353
Output #3
112633322
API Response (JSON)
{
  "problem": {
    "name": "Square Constraints",
    "description": {
      "content": "Given is an integer $N$. How many permutations $(P_0,P_1,\\cdots,P_{2N-1})$ of $(0,1,\\cdots,2N-1)$ satisfy the following condition? *   For each $i$ $(0 \\leq i \\leq 2N-1)$, $N^2 \\leq i^2+P_i^2 \\leq (2",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc036_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is an integer $N$. How many permutations $(P_0,P_1,\\cdots,P_{2N-1})$ of $(0,1,\\cdots,2N-1)$ satisfy the following condition?\n\n*   For each $i$ $(0 \\leq i \\leq 2N-1)$, $N^2 \\leq i^2+P_i^2 \\leq (2...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments