#5948. [CERC 2021] Lines in a grid

    ID: 5948 传统题 8000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P13769数学2021莫比乌斯反演ICPC整除分块欧拉函数筛法CERC

[CERC 2021] Lines in a grid

[CERC 2021] Lines in a grid

题目描述

Suppose that we are given a $n \times n$ integer grid, e.g. $\{(i, j)\}_{i=0, j=0}^{n-1, n-1}$. Let $l_n$ be the number of different lines that intersect with at least two points on the grid.

For n=3n = 3, there are exactly 20 such lines, as drawn on the image below.

:::align{center} :::

Compute lnl_n for all given nn.

输入格式

First line contains an integer $Q$ – the number of queries. The second line contains $Q$ space-separated integers $n_1, \ldots, n_Q$.

输出格式

Print $Q$ numbers $l_{n_1}, \ldots, l_{n_Q}$, each in its own line. Since $l_k$ can be large, print them modulo $10^6 + 3$.
3
1 3 2
0
20
6

提示

### Input limits
  • 1≤Q≤10001 \leq Q \leq 1000
  • 1≤ni≤1071 \leq n_i \leq 10^7 标签: P13769|数学|2021|莫比乌斯反演|ICPC|整除分块|欧拉函数|筛法|CERC

来源

P13769|[CERC 2021] Lines in a grid