Lines in a grid
Time limit8sMemory limit1024 MB
Count the distinct lines through at least two points of an n by n integer grid for each query n, modulo 1000003.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Combinatorics
- Solved
- No attempts yet
Problem
Suppose that we are given an integer grid, for example . Let be the number of different lines that intersect at least two points of the grid.
For , there are exactly 20 such lines, as drawn in the image below.

Compute for all given .
Input
The first line contains an integer , the number of queries. The second line contains space-separated integers .
Output
Print numbers , each on its own line. Since can be large, print each value modulo .
Constraints