Statistics

Problem Statement for "Mortgage"

Problem Statement

When purchasing a new home, the purchasers often take out a loan to pay for it. In this problem, we will be considering loans with the following terms:
  • At the beginning of each month, the purchasers pay a fixed amount towards settling the loan, which decreases the amount they owe.
  • At the end of the month, the amount the purchasers owe increases due to interest. Each month, 1/12 of the annual interest rate is added to the amount owed. Hence, if the annual interest rate is 12%, then the debt increases by 1% each month. You may assume that the amount owed after adding interest is always rounded up to the nearest dollar greater than or equal to the actual value.
Your task is, given the annual interest rate in tenths of a percent, the original amount of the loan, and the period over which the loan is to be repaid, calculate the minimum integral monthly payment so that the loan is repaid in term years or less. All monetary units are in dollars.

For example, if loan = 1000, interest = 50, and term = 1, then the loan is for $1000, to be paid back in one year, at an annual interest rate of 5%, or (5/12)% per month. If the purchasers pay back $86 every month, then the total amount owed will be as follows after each month:
month | after making payment | after interest accrues
------+----------------------+------------------------------------
 1    | 1000 - 86 = 914      | ceiling(914 * (1 + 5/12/100)) = 918
 2    | 918 - 86  = 832      | ceiling(832 * (1 + 5/12/100)) = 836
 3    | 836 - 86  = 750      | 754
 4    | 754 - 86  = 668      | 671
 5    | 671 - 86  = 585      | 588
 6    | 588 - 86  = 502      | 505
 7    | 505 - 86  = 419      | 421
 8    | 421 - 86  = 335      | 337
 9    | 337 - 86  = 251      | 253
 10   | 253 - 86  = 167      | 168
 11   | 168 - 86  = 82       | 83
 12   | 86 is more than enough to pay off the rest 
Clearly, 85 a month wouldn't be enough, since we just barely paid off the loan at 86.

Definition

Class:
Mortgage
Method:
monthlyPayment
Parameters:
int, int, int
Returns:
int
Method signature:
int monthlyPayment(int loan, int interest, int term)
(be sure your method is public)

Constraints

  • loan will be between 100 and 2,000,000,000, inclusive.
  • interest will be between 1 and 1,000,000, inclusive.
  • term will be between 1 and 1000, inclusive.

Examples

  1. 1000

    50

    1

    Returns: 86

    From the problem statement.

  2. 2000000000

    6000

    1

    Returns: 671844808

    interest = 6000 means that the monthly interest is a whopping 50%!

  3. 1000000

    1000000

    1000

    Returns: 988143

    The interest is so high that even if we had 1000 years to pay back the loan, we'd still have to pay almost a million dollars a month.

  4. 1000000

    129

    30

    Returns: 10868

  5. 100

    1

    1000

    Returns: 2

  6. 618083873

    932377

    462

    Returns: 610230012

  7. 37007334

    497647

    389

    Returns: 36135971

  8. 910806859

    106489

    245

    Returns: 818564691

  9. 620972289

    447604

    815

    Returns: 604759055

  10. 1964106774

    57176

    469

    Returns: 1623392057

  11. 396495408

    965433

    303

    Returns: 391627612

  12. 1303970803

    751105

    470

    Returns: 1283465566

  13. 560290889

    94158

    606

    Returns: 496956137

  14. 1193263809

    406909

    59

    Returns: 1159081766

  15. 790990757

    569741

    255

    Returns: 774674409

  16. 1878848491

    765597

    345

    Returns: 1849853804

  17. 1767005838

    159220

    890

    Returns: 1643164757

  18. 160606687

    352973

    961

    Returns: 155326077

  19. 468903894

    557830

    713

    Returns: 459029289

  20. 622058302

    712197

    633

    Returns: 611750749

  21. 804652054

    4523

    437

    Returns: 220265161

  22. 317486105

    626173

    530

    Returns: 311516199

  23. 1266328720

    680421

    78

    Returns: 1244382615

  24. 133678780

    660664

    497

    Returns: 131294016

  25. 180769391

    462677

    325

    Returns: 176199478

  26. 645338021

    625478

    616

    Returns: 633190063

  27. 534515614

    800188

    584

    Returns: 526618197

  28. 705069909

    347802

    229

    Returns: 681554646

  29. 614051902

    656351

    585

    Returns: 603026823

  30. 721647343

    325968

    970

    Returns: 696024302

  31. 1214770213

    843509

    161

    Returns: 1197730951

  32. 925650314

    407094

    289

    Returns: 899145989

  33. 1992772528

    53725

    966

    Returns: 1628934258

  34. 327822429

    896518

    882

    Returns: 323492445

  35. 1280563618

    750707

    121

    Returns: 1260415956

  36. 1114588932

    332313

    22

    Returns: 1075743268

  37. 61085060

    497791

    148

    Returns: 59647176

  38. 239835955

    918655

    492

    Returns: 236743476

  39. 252618379

    388703

    450

    Returns: 245053124

  40. 1157290063

    733456

    947

    Returns: 1138660553

  41. 259665595

    69925

    161

    Returns: 221630965

  42. 929938417

    686154

    508

    Returns: 913954464

  43. 175138409

    695122

    926

    Returns: 172166276

  44. 1495989673

    426673

    394

    Returns: 1455066535

  45. 1041972280

    681297

    337

    Returns: 1023937200

  46. 1382590995

    11132

    41

    Returns: 665355481

  47. 265538953

    562037

    137

    Returns: 259987974

  48. 1981832936

    758911

    487

    Returns: 1950983727

  49. 512042040

    323687

    861

    Returns: 493737774

  50. 163543995

    973173

    738

    Returns: 161551931

  51. 1511988723

    580548

    752

    Returns: 1481368648

  52. 1490110002

    305117

    39

    Returns: 1433722865

  53. 1463035902

    147540

    281

    Returns: 1352991833

  54. 1378407427

    121376

    802

    Returns: 1254390445

  55. 1939524178

    2486

    309

    Returns: 332849450

  56. 182518

    88

    197

    Returns: 1330

  57. 87128

    96

    279

    Returns: 693

  58. 184597

    40

    497

    Returns: 615

  59. 72135

    69

    268

    Returns: 414

  60. 179135

    74

    12

    Returns: 1870

  61. 48826

    32

    424

    Returns: 131

  62. 41875

    84

    677

    Returns: 293

  63. 177616

    57

    625

    Returns: 841

  64. 77336

    83

    661

    Returns: 533

  65. 13115

    25

    82

    Returns: 32

  66. 187890

    49

    103

    Returns: 770

  67. 164227

    44

    706

    Returns: 601

  68. 138709

    23

    280

    Returns: 267

  69. 9303

    82

    1000

    Returns: 65

  70. 14512

    15

    310

    Returns: 20

  71. 151273

    73

    895

    Returns: 916

  72. 127121

    6

    846

    Returns: 65

  73. 143038

    65

    879

    Returns: 772

  74. 126061

    53

    955

    Returns: 556

  75. 113753

    76

    387

    Returns: 717

  76. 1999999999

    1000000

    1

    Returns: 1976284585

  77. 2000000000

    6000

    1

    Returns: 671844808

  78. 20000000

    46

    999

    Returns: 76375

  79. 1000000

    1000000

    1000

    Returns: 988143

  80. 1999999999

    1000000

    1

    Returns: 1976284585

  81. 1999999997

    100000

    1

    Returns: 1785714284

  82. 1000

    50

    1

    Returns: 86

  83. 3948234

    984

    73

    Returns: 299221

  84. 2000000000

    1

    1000

    Returns: 263648


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: