<?php
function calcCreditSum($creditPerc, $commission, $price, $pay) {
for ($i=0; $i < 20; $i++) {
$price += $price * $creditPerc / 100 + $commission;
if($price <= $pay){
break;
}
$price -= $pay;
}
$price += $i*$pay;
return $price;
}
function calcCreditSumPzdc($creditPerc, $commission, $price, $pay) {
$price += $commission;
for ($i=0; $i < 20; $i++) {
$price += $creditPerc * $price / 100;
if ($price <= $pay){
break;
}
$price -= $pay;
}
$price += $i*$pay;
return $price;
}
$pay = 5000;
$price = 39999;
$balance = calcCreditSum(4, 500, $price, $pay);
echo "Hmcrdt: {$balance}\n";
$balance = calcCreditSum(3, 1000, $price, $pay);
echo "yobabank: {$balance}\n";
$balance = calcCreditSumPzdc(2, 7777, $price, $pay);
echo "pzdc: {$balance}\n";
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCgpmdW5jdGlvbiBjYWxjQ3JlZGl0U3VtKCRjcmVkaXRQZXJjLCAkY29tbWlzc2lvbiwgJHByaWNlLCAkcGF5KSB7CgkKCiAgICBmb3IgKCRpPTA7ICRpIDwgMjA7ICRpKyspIHsKICAgIAkKICAgIAkkcHJpY2UgKz0gJHByaWNlICogJGNyZWRpdFBlcmMgLyAxMDAgKyAkY29tbWlzc2lvbjsKICAgIAkKICAgIAlpZigkcHJpY2UgPD0gJHBheSl7CiAgICAJCQogICAgCQlicmVhazsKICAgIAl9CiAgICAJJHByaWNlIC09ICRwYXk7Cgl9CgkKCSRwcmljZSArPSAkaSokcGF5OwoJcmV0dXJuICRwcmljZTsKfQoKZnVuY3Rpb24gY2FsY0NyZWRpdFN1bVB6ZGMoJGNyZWRpdFBlcmMsICRjb21taXNzaW9uLCAkcHJpY2UsICRwYXkpIHsKCQoJJHByaWNlICs9ICRjb21taXNzaW9uOwoJCiAgICBmb3IgKCRpPTA7ICRpIDwgMjA7ICRpKyspIHsKICAgIAogICAgCSRwcmljZSArPSAkY3JlZGl0UGVyYyAqICRwcmljZSAvIDEwMDsKICAgIAkKICAgIAlpZiAoJHBy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