F - Increment All Divisors 解説 by en_translator
Original proposer: vwxyz
Suppose we can make all elements of \(A\) equal to \(x\).
Let us write the number of operations with \(i\) as \(C_i\). Then \(x\) can be written as a linear function of \(x\).
For \(i=N,N-1,\dots,1\) in order, find the coefficient of the first degree of the linear function of \(x\) representing \(C_i\). Then, \(C_i\) is only affected by \(C_{2i},C_{3i},\dots\), so they can be found in a total of \(O(N\log{N})\) time.
\(C_i\) is at least \(0\), which bounds the range of \(x\). Conversely, given any \(x\) that makes all \(C_i\) at least \(0\), it is always possible to make \(A\) equal to \(x\).
If there is no non-negative integer \(x\) within this range, the answer is \(-1\).
Suppose there exists a non-negative integer \(x\) within the range.
Choosing any \(i\) in an operation adds \(1\) to \(A_1\), so the minimum number of operations required to make all elements equal to \(x\) is \(x-A_1\).
Hence, the answer is \(x-A_1\) for the minimum such \(x\).
投稿日時:
最終更新: