#P4620. [SDOI2018] 荣誉称号
[SDOI2018] 荣誉称号
Description
Casual game player has not only achieved excellent results in algorithm contests, but also ranks very high in a diamond-collecting game.
This game has different types of diamonds, numbered from to . Player has played this game for a long time. For type , he has already collected diamonds. The biggest feature of this game is that there is only one way to obtain diamonds: buying them from the shop. Specifically, the unit price of type is coupons. To encourage players to spend money, there is no quantity limit for any type of diamond: as long as you are willing to pay, you can have as many diamonds as you want. However, the game does not have a “discard item” feature, so cannot discard diamonds to complete the task.
Recently, the game launched a limited-time achievement task. Players who complete it can get an honorary title. The completion condition is:
Given positive integers and , for any integer , the value
$a_{x}+a_{\lfloor\frac{x}{2}\rfloor}+a_{\lfloor\frac{x}{4}\rfloor}+a_{\lfloor\frac{x}{8}\rfloor}+...+a_{\lfloor\frac{x}{2^k}\rfloor}$
must be a multiple of .
Of course, skilled player wants to complete this limited-time achievement task, but before spending money he wants to know how many coupons he needs to complete it. Please write a program to help compute the minimum number of coupons required.
Input Format
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains positive integers , where is the number of diamond types, and are the task conditions.
To reduce the input size to some extent, arrays and are generated by the following code:
unsigned int SA, SB, SC;int p, A, B;
unsigned int rng61(){
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
void gen(){
scanf("%d%d%d%d%u%u%u%d%d", &n, &k, &m, &p, &SA, &SB, &SC, &A, &B);
for(int i = 1; i <= p; i++)scanf("%d%d", &a[i], &b[i]);
for(int i = p + 1; i <= n; i++){
a[i] = rng61() % A + 1;
b[i] = rng61() % B + 1;
}
}
Output Format
For each test case, output one integer per line, the minimum number of coupons required.
2
3 1 2 3 11111 22222 33333 1 1
1 5
2 3
3 6
7 2 3 7 11111 22222 33333 1 1
6 9
4 5
3 7
5 2
2 4
1 7
9 6
3
14
Hint
- .
- and .
- , .
- .
Constraints:
Subtask 1 ( points): and .
Subtask 2 ( points): and .
Subtask 3 ( points): and .
Translated by ChatGPT 5
京公网安备 11011102002149号