luogu#P4191. [CTSC2010] 性能优化

    ID: 3124 远端评测题 6000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2010分治素数判断,质数,筛法快速傅里叶变换 FFTCTSC/CTS

[CTSC2010] 性能优化

Background

Description

Programmer Xiao Ming is developing a large software system. There is a core routine described by the following pseudocode (assume all variables are initially 00, and that none of the data types will overflow):

Input a[0], a[1], ... , a[n - 1], b[0], b[1], ... , b[n - 1], C
For i: 0 to n - 1
	x[0, i] = a[i]
For i: 0 to C - 1
	For j: 0 to n - 1
		For k: 0 to n - 1
			x[i + 1, (j + k) mod n] = x[i + 1, (j + k) mod n] + b[k]x[i, j]
Output x[C, 0] mod (n + 1), x[C, 1] mod (n + 1), ... , x[C, n - 1] mod (n + 1)

However, this program is very inefficient; its time complexity is Θ(n2C)\Theta(n^2 C). He wants you to optimize this program while producing the same output. To make the problem easier, he guarantees that the input nn can be written as a product of some positive integers, each no greater than 1010, and that n+1n + 1 is prime.

Output Format

Output contains nn lines, one number per line. The ii-th line is the value of xC,imod(n+1)x_{C, i} \bmod (n + 1). You should ensure each printed number is between 00 and nn inclusive.

4 1
1 2 3 4
4 3 3 1

2
1
0
2

Hint

There are 1010 test points in total. Constraints:

Test Point nn CC
1 100\leq 100 100\leq 100
2 109\leq 10^9
3 700\leq 700
4
5 104\leq 10^4 =1 = 1
6 105\leq 10^5 =1= 1
7
8 5×105\leq 5 \times 10^5 109\leq 10^9
9
10

In all testdata, aia_i and bib_i do not exceed 10910^9.

Translated by ChatGPT 5