Minimum Operation
You are given positive integers $N$ and $M$ $(M \geq 2)$. You are also given an array $A$ of size $N$, such that $2 \leq A_i \leq M$. In one operation on the array, you can: - Select an integer $X$ $(2 \leq X \leq M)$ and change $A_i$ to $\gcd(A_i,X)$ for **all** $1 \leq i \leq N$. Note that $\gcd$ denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start