Intergalactic Mortgage
InterviewTime limit1sMemory limit128 MB
Simulate monthly compound interest at r/12 percent on a debt, subtract a fixed payment, and report whether the balance reaches zero within N years.
- Level
Medium4 of 10
- Topics
- Simulation, Math, Implementation, Binary search
- Solved
- No attempts yet
Problem
Many people on Earth want to solve their housing needs. When they don't have enough money to buy a house or a flat, they take a mortgage from a bank and then pay fixed monthly payments until the mortgage is fully repaid.
You may think that paying a mortgage for 30 years is a long time, but it is quite short compared to galactic mortgages. Aliens don't buy houses — they buy whole planets. Since planets are "a little" more expensive, the mortgage periods are much longer.
Mortgages work the same way for aliens as for us earthlings. If an alien wants to buy a planet, he goes to the GCB (Galactic Central Bank) to borrow an amount . The bank offers a mortgage with an annual interest rate of (per year). Interest is computed at the end of each month (one alien year has 12 months). At the end of every month, the current debt grows by , and then the alien pays the bank a fixed amount , which is subtracted from the debt.
Because of the intergalactic financial crisis, the bank's rules are strict. Every mortgage must start on the first day of a year. If, within the first years, the alien does not pay enough to cover the principal and interest, the bank confiscates his planet.
On the other hand, galactic employment is quite stable. Once you have a job, you keep it forever, so the alien can pay the same amount at the end of every month for the entire mortgage period.
Decide whether the alien is able to pay off his mortgage.
Input
The input contains several test cases. Each test case is given on one line containing the numbers , , , separated by spaces. is the principal (the initial amount borrowed), is the monthly payment (paid at the end of each month), is the number of years within which the alien must repay the mortgage, and is the annual interest rate in percent.
and are integers (). is an integer (). is a real number with two digits of precision (). For each test case, the values , , , are chosen so that even if the alien paid nothing for the whole time, the resulting debt after years would be at most . The precision of a double is also sufficient for most computations (a difference in the rate of less than will not affect the result).
The last test case is followed by a line containing four zeros.
Output
For each test case, output "YES" if the alien can repay the mortgage within years, and "NO" if his salary is too small to repay the mortgage in time.