#P8792. [蓝桥杯 2022 国 A] 最大公约数
[蓝桥杯 2022 国 A] 最大公约数
Problem Description
Given an array, in each operation you may choose any two adjacent elements in the array and replace one of them with , where denotes the greatest common divisor of and . Find the minimum number of operations needed to make the entire array contain only .
Input Format
The first line of input contains an integer , which denotes the length of the array.
The second line contains integers , separated by a single space between adjacent integers.
Output Format
Output one line containing one integer, which is the minimum number of operations. If it is impossible to meet the requirement no matter how you operate, output .
3
4 6 9
4
Hint
【Constraints and Conventions for Test Cases】
- For of the test cases, , .
- For of the test cases, , .
- For all test cases, , .
Lanqiao Cup 2022 National Contest Group A, Problem D.
Translated by ChatGPT 5