<?php
$total = 30;
$skip = 5;
if ($skip > $total) {
echo "Задача не имеет решения. Проверьте введёные данные.";
}
for ($participant = 0; $participant < $total; $participant++) {
$seats[$participant] = $participant + 1;
}
for ($participant = 0; $total >= $skip; $total--) {
if ($participant <= $total - $skip) {
$participant = $participant + $skip - 1;
unset($seats[$participant]);
continue;
}
$placeInNewCircle = -1;
for ($PlacesToEnd = $skip; $PlacesToEnd > 0; $PlacesToEnd--) {
$placeInNewCircle++;
if ($participant + $PlacesToEnd - 1 == $total) {
$participant = $placeInNewCircle;
break;
}
}
unset($seats[$participant]); }
echo "Выигрышные места: ".implode(", ", $seats);
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKIAokdG90YWwgPSAzMDsKJHNraXAgPSA1OwoKaWYgKCRza2lwID4gJHRvdGFsKSB7CgoJZWNobyAi0JfQsNC00LDRh9CwINC90LUg0LjQvNC10LXRgiDRgNC10YjQtdC90LjRjy4g0J/RgNC+0LLQtdGA0YzRgtC1INCy0LLQtdC00ZHQvdGL0LUg0LTQsNC90L3Ri9C1LiI7CglleGl0Owp9CiAKZm9yICgkcGFydGljaXBhbnQgPSAwOyAkcGFydGljaXBhbnQgPCAkdG90YWw7ICRwYXJ0aWNpcGFudCsrKSB7Cgkkc2VhdHNbJHBhcnRpY2lwYW50XSA9ICRwYXJ0aWNpcGFudCArIDE7Cn0KIApmb3IgKCRwYXJ0aWNpcGFudCA9IDA7ICR0b3RhbCA+PSAkc2tpcDsgJHRvdGFsLS0pIHsKCiAgICBpZiAoJHBhcnRpY2lwYW50IDw9ICR0b3RhbCAtICRza2lwKSB7CgogICAgCSRwYXJ0aWNpcGFudCA9ICRwYXJ0aWNpcGFudCArICRza2lwIC0gMTsKCiAgICAgICAgdW5zZXQoJHNlYXRzWyRwYXJ0aWNpcGFudF0pOwogICAgICAgIHNvcnQoJHNlYXRzKTsgIAoKICAgICAgICBjb250aW51ZTsgICA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