<?php
function payment($summa, $percent, $comission, $payback, $oneTimePay) {
$allpay = 0;
$summa += $oneTimePay;
for ($i = 1; $i < 20; $i++) {
$debt = $summa * $percent + $comission;
if ($debt < $payback) {
$payback = $summa * $percent + $comission;
$allpay +=$payback;
break;
} else {
$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";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBwYXltZW50KCRzdW1tYSwgJHBlcmNlbnQsICRjb21pc3Npb24sICRwYXliYWNrLCAkb25lVGltZVBheSkgewogICAgJGFsbHBheSA9IDA7CiAgICAkc3VtbWEgKz0gJG9uZVRpbWVQYXk7CiAgICBmb3IgKCRpID0gMTsgJGkgPCAyMDsgJGkrKykgewogICAgCSRkZWJ0ID0gJHN1bW1hICogJHBlcmNlbnQgKyAkY29taXNzaW9uOwogICAgICAgIGlmICgkZGVidCA8ICRwYXliYWNrKSB7CiAgICAgICAgICAgICRwYXliYWNrID0gJHN1bW1hICogJHBlcmNlbnQgKyAkY29taXNzaW9uOwogICAgICAgICAgICAkYWxscGF5ICs9JHBheWJhY2s7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgJHN1bW1hID0gJHN1bW1hICogJHBlcmNlbnQgKyAkY29taXNzaW9uIC0gJHBheWJhY2s7CiAgICAgICAgJGFsbHBheSArPSRwYXliYWNrOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAkYWxscGF5Owp9CiRob21vID0gcGF5bWVudCgzOTk5OSwgMS4wNCwgNTAwLCA1MDAwLCAwKTsKZWNobyAi0JIg0LPQvtC80L4g0LHQsNC90LrQtSDQv9C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