<?php
function payment($summa, $percent, $comission, $payback, $oneTimePay) {
$allpay = 0;
$summa += $oneTimePay;
for ($i = 1; $i < 20; $i++) {
if ($summa * $percent + $comission < $payback) {
$payback = $summa * $percent + $comission;
$summa = $summa * $percent + $comission - $payback;
$allpay +=$payback;
break;
};
$summa = $summa * $percent + $comission - $payback;
$allpay +=$payback;
};
return $allpay;
};
$homo = payment(39999, 1.04, 500, 5000, 0);
echo "В гомо банке платим {$homo} рублей\n";
$soft = payment(39999, 1.03, 1000, 5000, 0);
echo "В мягком банке платим {$soft} рублей\n";
$berry = payment(39999, 1.02, 0, 5000, 7777);
echo "В клубничном банке платим {$berry} рублей\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBwYXltZW50KCRzdW1tYSwgJHBlcmNlbnQsICRjb21pc3Npb24sICRwYXliYWNrLCAkb25lVGltZVBheSkgewogICAgJGFsbHBheSA9IDA7CiAgICAkc3VtbWEgKz0gJG9uZVRpbWVQYXk7CiAgICBmb3IgKCRpID0gMTsgJGkgPCAyMDsgJGkrKykgewogICAgICAgIGlmICgkc3VtbWEgKiAkcGVyY2VudCArICRjb21pc3Npb24gPCAkcGF5YmFjaykgewogICAgICAgICAgICAkcGF5YmFjayA9ICRzdW1tYSAqICRwZXJjZW50ICsgJGNvbWlzc2lvbjsKICAgICAgICAgICAgJHN1bW1hID0gJHN1bW1hICogJHBlcmNlbnQgKyAkY29taXNzaW9uIC0gJHBheWJhY2s7CiAgICAgICAgICAgICRhbGxwYXkgKz0kcGF5YmFjazsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfTsKICAgICAgICAkc3VtbWEgPSAkc3VtbWEgKiAkcGVyY2VudCArICRjb21pc3Npb24gLSAkcGF5YmFjazsKICAgICAgICAkYWxscGF5ICs9JHBheWJhY2s7CiAgICB9OwogICAgcmV0dXJuICRhbGxwYXk7Cn07CiRob21vID0gcGF5bWVudCgzOTk5OSwgMS4wNCwgNTAwLCA1MDAwLCA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