Все вышеупомянутые ответы корректны, насколько я могу сказать, таким образом, я собираюсь сказать Вам что-то еще. Поскольку производство кодирует Вас, действительно должен использовать классы в java.util.concurrent. Существует очень мало, они не могут сделать для Вас в области параллелизма в Java.
The key insight is that the total remainder is equal to the sum of the individual remainders when calculating each result[i]
.
Since each individual remainder is the result of rounding down, it is at most 1. There are results.length
such remainders, so the total remainder is at most results.length
.
EDIT: Obviously it's not a proof without some pretty symbols, so here are some...
Подтверждение не требуется.
Базовые суммы распределяются простым делением с округлением в меньшую сторону. So the allocated amount will always be less than or equal to the total.
Remainder contains the unallocated amount. Which will always be a whole number less than 'i'. So he simply gives each receiver 1 until the money is gone.
Простой
просто используйте тот факт, что
a = floor (a / b) * b + (a% b)
I'd say it's not correct because some curious ratio could cause a remainder greater then the number of results. Therefore I suggest results[i % results.length].amount++;
.
Edit: I withdraw my answer. With longs there's no curious ratio and with floating point modulo doesn't help