values and a short list divisors. In one step you can increase any number in values by 1.
For every d in divisors, at least one number in values must be divisible by d. A single number may cover several divisors at once.
Return the minimum number of steps needed.values=[7, 13], divisors=[3, 4] → 3
Raising 7 to 9 (divisible by 3) and 13 to 16 (by 4) costs 2 + 3 = 5. Raising 13 to 15 (by 3) and 7 to 8 (by 4) costs 2 + 1 = 3, which is better. Taking one number to 12, divisible by both, costs at least 5.
values=[5, 9], divisors=[6, 3] → 1
Raising 5 to 6 is enough: 6 is divisible by both 6 and 3.
values=[10, 1], divisors=[5] → 0
values=[7, 13], divisors=[3, 4]
3
Run checks the first 3 tests in your browser. Submit checks all 160 tests on the server, hidden ones included.