#P2025. Dirichlet 半在线卷积

    ID: 11557 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创Dirichlet 卷积欧拉函数

Dirichlet 半在线卷积

Description

Given a function ff satisfying f(1)=1f(1)=1, and

f(n)=dn,d<nf(d)φ(n/d).f(n)=\sum_{d|n,d<n}f(d)\varphi(n/d).

Given a positive integer nn, compute the values f(1),f(2),,f(n)f(1), f(2), \cdots, f(n). To control the output size, you only need to output the value of the following expression:

k=1n(f(k)mod232).\bigoplus_{k=1}^n\left(f(k)\bmod 2^{32}\right).

Here \oplus denotes xor.

Input Format

One line with a positive integer nn.

Output Format

One line with a non-negative integer, representing the value of k=1n(f(k)mod232)\bigoplus_{k=1}^n\left(f(k)\bmod 2^{32}\right).

10
10
1000000
3527171714
10000000
191685100

Hint

For all testdata, 1n5×1071 \le n \le 5 \times 10^7.

For Sample 1, the first 1010 terms of ff are: 1,1,2,3,4,6,6,9,10,121, 1, 2, 3, 4, 6, 6, 9, 10, 12.

The time limit is 1.51.5 times that of std.

Translated by ChatGPT 5