Product Modulo

AtCoder
IDagc047_c
Time2000ms
Memory256MB
Difficulty
Let’s take a prime $P = 200\,003$. You are given $N$ integers $A_1, A_2, \ldots, A_N$. Find the sum of $((A_i \cdot A_j) \bmod P)$ over all $N \cdot (N-1) / 2$ unordered pairs of elements ($i < j$). Please note that the sum isn't computed modulo $P$. ## Constraints * $2 \leq N \leq 200\,000$ * $0 \leq A_i < P = 200\,003$ * All values in input are integers. ## Input Input is given from Standard Input in the following format. $N$ $A_1$ $A_2$ $\cdots$ $A_N$ [samples]
Samples
Input #1
4
2019 0 2020 200002
Output #1
474287

The non-zero products are:

*   $2019 \cdot 2020 \bmod P = 78320$
*   $2019 \cdot 200002 \bmod P = 197984$
*   $2020 \cdot 200002 \bmod P = 197983$

So the answer is $0 + 78320 + 197984 + 0 + 0 + 197983 = 474287$.
Input #2
5
1 1 2 2 100000
Output #2
600013
API Response (JSON)
{
  "problem": {
    "name": "Product Modulo",
    "description": {
      "content": "Let’s take a prime $P = 200\\,003$. You are given $N$ integers $A_1, A_2, \\ldots, A_N$. Find the sum of $((A_i \\cdot A_j) \\bmod P)$ over all $N \\cdot (N-1) / 2$ unordered pairs of elements ($i < j$). P",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc047_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let’s take a prime $P = 200\\,003$. You are given $N$ integers $A_1, A_2, \\ldots, A_N$. Find the sum of $((A_i \\cdot A_j) \\bmod P)$ over all $N \\cdot (N-1) / 2$ unordered pairs of elements ($i < j$).\nP...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments