<?php
function getBatchSize($n) {
if ($n <= 100) return false;
for ($k = 1; $k <= 50; $k++) {
// number of batches without the last (remainder) batch
$x = floor((100.0 / (float)$k) - 1);
// batch-size wihout the last batch
$b = floor($n / $x);
// remainder (batch-size of the last batch)
$r = $n - ($b * $x);
// remainder-limit (the acceptable remainder-size)
$rl = ceil(($n / $x) * 2.0);
if ($r <= $rl) break;
}
$pInc = floor(100.0 / $x);
$pSum = $pInc * $x;
$pR = 100 - $pSum;
return array(
'b' => $b,
'x' => $x,
'r' => $r,
'pInc' => $pInc,
'pSum' => $pSum,
'pR' => $pR
);
}
$n = 101;
$res = getBatchSize($n);
if ($res === false) {
printResult("n <= 100");
return;
}
echo "Resolve for n = " . $n . "<br />=> b = " . $res['b'] . ", x = " . $res['x'] . ", r = "
. $res['r'] . ", pInc = " . $res['pInc'] . ", pSum = " . $res['pSum'] . ", pR = " . $res['pR'];
echo "<br />";
for ($k = 1; $k <= 50; $k++) {
$x = floor((100.0 / (float)$k) - 1.0);
$b = floor($n / $x);
$r = $n - ($b * $x);
$rl = ceil(($n / $x) * 2.0);
//
$str = "k = " . $k;
$str .= ", b = " . $b;
$str .= ", x = " . $x;
$str .= ": (" . $r . ' ≤ ' . $rl . ")";
if ($r <= $rl) $str .= " => [OK]";
echo '<br />' . $str;
}
preferences:
48.02 ms | 402 KiB | 5 Q