#P5379. [THUPC 2019] 令人难以忘记的题目名称
[THUPC 2019] 令人难以忘记的题目名称
Description
Now there is an integer sequence of length (indexed from ). Alice and Bob play a game on this sequence.
The game proceeds in rounds. In each round:
- Alice provides a positive integer sequence of length .
- Bob sees the given by Alice, then chooses an integer in .
- Then we transform into by the following rule:
- Take as the new , and this round ends.
If after some round ends, every number in is a multiple of a given prime , then Alice wins.
Given and the initial sequence , determine whether Alice can guarantee a win in finitely many steps. If yes, what is the minimum number of rounds in which she can guarantee a win.
Input Format
The first line contains two non-negative integers , and is guaranteed to be a prime.
The next line contains integers separated by spaces, describing the initial sequence ().
It is guaranteed that and .
Output Format
Output one integer. If Alice cannot guarantee a win in finitely many steps, output . Otherwise, output an integer indicating the minimum number of rounds in which Alice can win.
4 2
0 1 0 1
2
Hint
Sample Explanation
One possible game process is:
- Round 1: , , and the transformed sequence is .
- Round 2: . No matter what is, the transformed sequence is .
It can be proved that rounds is optimal.
Copyright Information
From THUPC (THU Programming Contest, Tsinghua University Programming Contest) 2019.
Resources such as solutions can be found at https://github.com/wangyurzee7/THUPC2019.
Translated by ChatGPT 5
京公网安备 11011102002149号