We iterate from a brute-force pair check through a divisor sieve, then drop the constant factor with numpy. Inverting the question into a sieve avoids checking every pair.
We iterate from a brute-force pair check through a divisor sieve, then drop the constant factor with numpy. Inverting the question into a sieve avoids checking every pair.
You are given an integer array nums.
You can perform the following operation any number of times:
a and b such that nums[a] % nums[b] == 0.nums[a] with nums[b].Return the minimum possible sum of the array after performing any number of operations.