
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think about gcd(n, k). How will it help to calculate the answer?
indices i and j are in the same group if gcd(n, k) mod i = gcd(n, k) mod j. Each group should have equal elements. Think about the minimum number of operations for each group
The minimum number of operations for each group equals the summation of differences between the elements and the median of elements inside the group.