#P4527. [CTSC2008] 奥运抽奖
[CTSC2008] 奥运抽奖
Description
With days left before the opening of the Beijing Olympics, CTSC plans to hold a lottery for volunteers. As one of the volunteers, you are very excited about it.
The CTSC committee introduces the rules. Suppose there are volunteers in total. At the beginning, each volunteer receives a distinct number from to .
In the center of the screen are the avatars of the five Fuwa (Beibei, Jingjing, Huanhuan, Yingying, Nini), blinking to welcome everyone. When the lottery starts, the staff presses the button next to the screen and waits for the screen to stop. At that moment, the Fuwa stop blinking.
Of course, when the screen stops, some Fuwa may have their eyes open while others have them closed. If all Fuwa have their eyes closed, the staff presses the button again, repeating this until at least one Fuwa has eyes open. Then, the staff observes which Fuwa have their eyes open.
The five Fuwa are labeled as follows: Beibei, Jingjing, Huanhuan, Yingying, Nini are labeled , , , , respectively (the staff think and are not good numbers). Lucky numbers are defined as follows:
- If a Fuwa’s eyes are open, then his/her label is a lucky number.
- If numbers and (possibly equal) are lucky numbers, then their product is also a lucky number.
- All other numbers are not lucky.
Let denote the set of all lucky numbers. For example, if Beibei and Jingjing have eyes open while Huanhuan, Yingying, and Nini have eyes closed, then . Let denote the -th lucky number in ascending order. For example, in the above case, , , and so on.
Next, the staff randomly generates two numbers; let the smaller one be and the larger one be . Define the set by
$$T_{a,b}=\{\,d \mid d\in L,\ l(a)\mid d,\ d\mid l(b)\,\}$$(where means divides ).
Define the characteristic value of a finite subset of natural numbers as follows:
- The characteristic value of the empty set is .
- For a non-empty set , let be the smallest element of . Then
where denotes the set obtained by removing the element from , and is a given non-negative integer.
After and are generated, the winner’s number is the remainder when is divided by . The staff will generate many pairs , thus producing multiple winners.
However, the on-site program takes a long time to compute the winners. Eager to know the results, you decide to rewrite the computation program, and your eyes turn to the keyboard in front of you.
Input Format
The first line contains five space-separated numbers, each either or , indicating whether Beibei, Jingjing, Huanhuan, Yingying, and Nini have their eyes open. Here means closed and means open. The numbers cannot all be .
The second line contains two space-separated numbers and . Here is the number of volunteers, and is as described above for computing the characteristic value of a set.
The third line contains the number , the number of generated pairs .
Each of the next lines contains two space-separated integers and , representing one lottery draw.
Output Format
Output lines, each containing one integer, the winner’s number for that draw. The order corresponds one-to-one with the pairs in the input. Of course, a person may win multiple times.
1 0 0 1 0
10001 2
3
1 10
2 12
4 15
3265
5816
0
Hint
Sample explanation:
Beibei and Yingying have their eyes open. Therefore, the first lucky numbers are .
, . The lucky numbers that are multiples of and divisors of are . So . The characteristic value of is computed as follows:
$f(\{8,10,20,40\})=8+34870+2\times8\times34870=592798$
$f(\{4,8,10,20,40\})=4+592798+2\times4\times592798=5335186$
$f(\{2,4,8,10,20,40\})=2+5335186+2\times2\times5335186=26675932$
Therefore, the winner’s number is the remainder of divided by , which is . Similarly, , whose characteristic value is , and its remainder modulo is . Also, .
Constraints:
- For of the testdata, , .
- For of the testdata, is prime.
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号