#P10186. Lattice Line Affection

    ID: 12178 Type: Default 1000ms 256MiB

Lattice Line Affection

Lattice Line Affection

Given a square lattice of points with coordinates from \((1,1)\) to \((n,n)\), and a line with the equation \(y=kx\) where \(k\in (0,\infty)\), the line will pass through some of the lattice points. For any value of \(k\), let \(cnt\) denote the number of lattice points that lie on the line. The affection level for that line is defined as \(cnt^2\).

Note that if \(k\) is irrational, then the line does not pass through any lattice point. If \(k\) is rational, then it can be expressed uniquely in lowest terms as \(k=\frac{a}{b}\) with \(\gcd(a,b)=1\). The lattice points lying on the line are exactly of the form \((b\cdot t, a\cdot t)\) for positive integers \(t\) satisfying \[ b\cdot t\le n \quad \text{and} \quad a\cdot t\le n, \] which is equivalent to \(t\le \left\lfloor \frac{n}{\max(a,b)} \right\rfloor\). Thus, the number of lattice points on the line is \[ cnt = \left\lfloor \frac{n}{\max(a,b)} \right\rfloor\,, \] and the corresponding affection level is \[ cnt^2 = \left(\left\lfloor \frac{n}{\max(a,b)} \right\rfloor\right)^2\,. \]

Your task is to compute the sum of affection levels for all lines of the form \(y=kx\) (with \(k\in(0,\infty)\)) that pass through at least one lattice point, modulo \(10^9+7\). In other words, the answer is given by \[ \sum_{\substack{(a,b)\in \mathbb{Z}^+\times \mathbb{Z}^+ \\ \gcd(a,b)=1,\; \max(a,b)\le n}} \left(\left\lfloor \frac{n}{\max(a,b)} \right\rfloor\right)^2 \pmod{10^9+7}. \]

inputFormat

The input consists of a single integer \(n\), representing the size of the lattice grid.

Constraints: \(1 \le n \le 10^6\).

outputFormat

Output a single integer: the sum of affection levels modulo \(10^9+7\).

sample

2
6