#P13769. [CERC 2021] Lines in a grid

[CERC 2021] Lines in a grid

题目描述

Suppose that we are given a n×nn \times n integer grid, e.g. {(i,j)}i=0,j=0n1,n1\{(i, j)\}_{i=0, j=0}^{n-1, n-1}. Let lnl_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 QQ – the number of queries. The second line contains QQ space-separated integers n1,,nQn_1, \ldots, n_Q.

输出格式

Print QQ numbers ln1,,lnQl_{n_1}, \ldots, l_{n_Q}, each in its own line. Since lkl_k can be large, print them modulo 106+310^6 + 3.

3
1 3 2
0
20
6

提示

Input limits

  • 1Q10001 \leq Q \leq 1000
  • 1ni1071 \leq n_i \leq 10^7