luogu#P8155. 「PMOI-5」公约数变换
「PMOI-5」公约数变换
Problem Description
You are given a constant and a sequence of length .
Define one "common divisor transformation" as follows:
First set , and finally set . (Note that you must compute all first and then assign them to one by one, rather than computing and assigning at the same time.)
Find the minimum number of "common divisor transformations" needed so that , .
It can be proven that a solution always exists.
Input Format
The first line contains two integers and , representing the length of the sequence and the given constant.
The next line contains integers, where the -th integer is .
Output Format
Output one integer in a single line, representing the answer.
5 5
5 4 3 2 1
4
10 6154
1 3 6 4 2 5 7 8 1 2
263
Hint
[Sample Explanation 1]
After the first "common divisor transformation", the sequence becomes .
After the second "common divisor transformation", the sequence becomes .
After the third "common divisor transformation", the sequence becomes .
After the fourth "common divisor transformation", the sequence becomes .
So the answer is .
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (5 pts): .
- Subtask 2 (10 pts): .
- Subtask 3 (10 pts): and .
- Subtask 4 (15 pts): .
- Subtask 5 (10 pts): .
- Subtask 6 (20 pts): .
- Subtask 7 (10 pts): .
- Subtask 8 (20 pts): No special constraints.
For of the testdata, , , . It is guaranteed that the answer fits in long long.
Translated by ChatGPT 5