#P7704. 「MCOI-09」Greedy Deletion
「MCOI-09」Greedy Deletion
Description
Positive integers less than or equal to form the set .
The cost to delete the element with value is , and each element can be deleted at most once.
Given positive integers and , find: what is the minimum cost to make the product of all elements in a perfect square? Output the answer modulo .
Note that you need to minimize the cost first, then take modulo , rather than minimizing the cost after taking modulo .
You need to answer queries, and all queries share the same .
Input Format
The first line contains three positive integers , , and , representing the number of queries, the given , and the maximum .
The next lines each contain one positive integer .
Output Format
Output lines. On the -th line, output the answer for the -th query.
2 2 6
1
6
0
25
Hint
Explanation for Sample 1
For , the product of is a perfect square, so no deletion is needed.
For , you can delete to make the product of a perfect square.
Constraints
- Subtask 1 (7 pts): .
- Subtask 2 (37 pts): .
- Subtask 3 (11 pts): .
- Subtask 4 (45 pts): no additional constraints.
For of the testdata, , , .
It is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号