<?php
	error_reporting(-1);
	$credit=39999;
	$payment=5000;
	$persent=1.03;
	$service=1000;
	$total=0;
	$mon=0;
		for ($credit=40000; $credit>0; $credit=($credit*$persent+$service)-$payment)
		{
			if ($credit+$service<5000)
				{	
					$mon++;
					$credit=($credit+($credit*0.03+1000));
					$total=$total+$credit;
					break;
				}
			$mon++;
			$total=$total+5000;
		}
	echo "Он отдал долг за $mon месяцев и заплатил: $total."
?>