#P6104. [EER2] 相同的数字

[EER2] 相同的数字

Description

Every morning, nn fixed numbers are written on the blackboard, but they are too messy, so every night the rabbit wants to make them become the same number.

There are two operations:

  • Choose an index kk and replace aka_k with ak+1a_k+1. Each operation costs c1c_1 time.

  • Choose an index kk and replace aka_k with the smallest prime that is greater than aka_k. Each operation costs c2c_2 time.

The rabbit is lazy, so he does not want to spend too much time. You need to help him compute the minimum time to make all numbers equal.

There are qq days in total. The rabbit’s state is different each day, so each day has different c1c_1 and c2c_2. But the numbers on the blackboard do not change.

The time spent on the first day will of course affect the state of the second day. The real cost each day is c1=c1(T×(lastansmod217))c_1 = c'_1\oplus (T \times (lastans \bmod 2^{17})), c2=c2(T×(lastansmod217))c_2 = c'_2 \oplus (T\times (lastans \bmod 2^{17})). Here \oplus is the xor\operatorname{xor} operation, and lastanslastans is the previous answer. Initially, lastans=0lastans = 0.

Input Format

The first line contains three integers n,q,Tn, q, T, representing the number of numbers on the blackboard, the total number of days, and a parameter.

The second line contains nn integers aia_i, representing the numbers on the blackboard.

The next qq lines each contain two integers c1,c2c'_1, c'_2, representing the parameters of the operation costs for that day.

Output Format

Output qq lines. Each line contains one integer, representing the minimum time for that day.

5 2 0
3 5 8 14 16
2 3
1 3

41
32

4 2 1
2 3 5 8
1 2
12 9

14
28

Hint

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1ai1071 \leq a_i \leq 10^7, 0T10 \leq T \leq 1, 1q1061 \leq q \leq 10^6, 1c1,c2,c1,c2<2171 \leq c_1, c_2, c'_1, c'_2< 2^{17}.

Test Point ID Score nn\leq aia_i\leq T=T= qq\leq Special Properties
11 1010 100100 00 55 All aia_i are primes, c1,c2104c_1, c_2\leq 10^4.
22 10510^5 10510^5
33 2525 10710^7
44 1010 11 All aia_i are primes.
55 2020 00 10510^5
66 2222 11 10610^6
77 3\color{red}3 Timelimit\color{red}{Time limit} 700ms\color{red}{700ms}.

Translated by ChatGPT 5