CodeTON Round 9 (Div. 1 + Div. 2, Rated, Prizes!)
F2
Shohag Loves Counting (Hard Version)
Codeforces
3200
原题
← F1G →
翻译中…

This is the hard version of the problem. The only differences between the two versions of this problem are the constraints on $t$, $m$, and the sum of $m$. You can only make hacks if both versions of the problem are solved.

翻译中…

For an integer array $a$ of length $n$, define $f(k)$ as the greatest common divisor (GCD) of the maximum values of all subarrays$^{\text{∗}}$ of length $k$. For example, if the array is $[2, 1, 4, 6, 2]$, then $f(3) = \operatorname{gcd}(\operatorname{max}([2, 1, 4]), \operatorname{max}([1, 4, 6]), \operatorname{max}([4, 6, 2])) = \operatorname{gcd}(4, 6, 6) = 2$.

翻译中…

An array is good if $f(i) \neq f(j)$ is satisfied over all pairs $1 \le i \lt j \le n$.

翻译中…

Shohag has an integer $m$. Help him count the number, modulo $998\,244\,353$, of non-empty good arrays of arbitrary length such that each element of the array is an integer from $1$ to $m$.

翻译中…

$^{\text{∗}}$An array $d$ is a subarray of an array $c$ if $d$ can be obtained from $c$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \le t \le 3 \cdot 10^5$) — the number of test cases.

翻译中…

The first and only line of each test case contains an integer $m$ ($1 \le m \le 10^6$).

翻译中…

Note that there is no limit on the sum of $m$ over all test cases.

翻译中…

Output

翻译中…

For each test case, output an integer — the number of valid arrays modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, the valid arrays are $[1]$, $[1, 2]$, $[2]$, and $[2, 1]$.

翻译中…

In the second test case, there are a total of $29$ valid arrays. In particular, the array $[2, 1, 4]$ with length $n = 3$ is valid because all elements are from $1$ to $m = 5$ and $f(1)$, $f(2)$ and $f(n = 3)$ all are distinct:

翻译中…
  • $f(1) = \operatorname{gcd}(\operatorname{max}([2]), \operatorname{max}([1]), \operatorname{max}([4])) = \operatorname{gcd}(2, 1, 4) = 1.$
  • $f(2) = \operatorname{gcd}(\operatorname{max}([2, 1]), \operatorname{max}([1, 4])) = \operatorname{gcd}(2, 4) = 2.$
  • $f(3) = \operatorname{gcd}(\operatorname{max}([2, 1, 4])) = \operatorname{gcd}(4) = 4.$
翻译中…

样例

Input #1
3
2
5
9
Output #1
4
29
165
InputCopy OutputCopy
题目信息
题号
2039F2
时间限制
4 s
内存限制
512 MB
标签
动态规划
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。