#P17254. 线性筛 2

    ID: 19746 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>O2优化大步小步算法 BSGS线性筛法

线性筛 2

Background

Stealing the testdata and directly printing the output to grab the best solution is a serious violation. Depending on the severity, your account may be permanently banned.

It got dark.
Then it got bright again.
The sun shines on this lowland,
shining on every tiny and precious life.

Problem Description

Given a multiplicative function ff and a modulus PP, for each 1≤n≤N1 \le n \le N, compute f(n)n mod Pf(n)^n \bmod P.

Input Format

The first line contains two positive integers N,PN, P.

Then there are π(N)\pi(N) lines. On the ii-th line there are ⌊log⁡piN⌋\left\lfloor\log_{p_i}N\right\rfloor integers; the jj-th integer is f(pij)f(p_i^j), where pip_i is the ii-th prime.

Output Format

Output one non-negative integer, which is ⨁n=1N(f(n)n mod P)\displaystyle\bigoplus_{n=1}^N (f(n)^n \bmod P).

20 1000000000
2 4 8 16
3 9
5
7
11
13
17
19
501702414

Hint

For all testdata, 1≤N≤3×1071 \le N \le 3 \times 10^7, 108≤P≤10910^8 \le P \le 10^9, 0≤f(pk)<P0 \le f(p^k) < P, and it is not guaranteed that PP is prime.

The time limit has been increased to more than 1.51.5 times that of std.

Translated by ChatGPT 5