#K58612. Lexicographically Smallest Array After GCD Operations
Lexicographically Smallest Array After GCD Operations
Lexicographically Smallest Array After GCD Operations
You are given an array of N positive integers and an integer M. Your task is to perform exactly M operations on the array such that the resulting array is lexicographically the smallest possible. It turns out that the optimal strategy is to replace every element by the greatest common divisor (GCD) of the entire array.
Formally, given an array (a_1, a_2, \ldots, a_N) and an integer M, the answer is an array ([g, g, \ldots, g]) where (g = \gcd(a_1, a_2, \ldots, a_N)).
inputFormat
The first line of input contains two integers N and M, where N is the number of elements in the array and M represents the number of operations. The second line contains N space-separated integers denoting the array elements.
outputFormat
Output the lexicographically smallest array after performing exactly M operations. Print N integers separated by a single space on a single line.## sample
5 1
12 15 9 18 24
3 3 3 3 3
</p>