Statistics

Problem Statement for "EllysChocolates"

Problem Statement

Have you ever heard the following riddle?

A shop sells one chocolate for one euro.
It also exchanges three chocolate wrappers for a new chocolate.
You have 15 euro. How many chocolates can you eat?


It is said that 90% of the people cannot get the correct answer. Since you are not humans but topcoders, Elly believes that 90% (or even more) of you can solve it. What did you get? The correct answer is 22.
Elly thinks that the problem has too many constants. One euro per chocolate. Three wrappers for a new chocolate. Fifteen euro. It can be made so much more generic! Now the girl has given you the following modified version:

A shop sells one chocolate for P euro.
It also exchanges K chocolate wrappers for a new chocolate.
You have N euro. How many chocolates can you eat?


Given the ints P, K, and N, return the maximum number of chocolates that can be eaten.

Definition

Class:
EllysChocolates
Method:
getCount
Parameters:
int, int, int
Returns:
int
Method signature:
int getCount(int P, int K, int N)
(be sure your method is public)

Constraints

  • P will be between 1 and 1,000, inclusive.
  • K will be between 2 and 1,000, inclusive.
  • N will be between 3 and 1,000,000, inclusive.

Examples

  1. 1

    3

    15

    Returns: 22

    Elly buys 15 chocolates with the money she has, eats them, and gets 15 wrappers. She then exchanges them for 5 new chocolates. After eating them as well, she has 5 wrappers, 3 of which she exchanges for a new chocolate. After eating it as well, she again has three wrappers, which she exchanges for one last chocolate.

  2. 41

    4

    1337

    Returns: 42

  3. 666

    13

    823172

    Returns: 1337

  4. 666

    222

    444

    Returns: 0

    In this case even a single chocolate costs more than the money Elly has, so she's unable to buy any.

  5. 1

    2

    1000000

    Returns: 1999999

  6. 1000

    1000

    1000000

    Returns: 1001

  7. 2

    11

    20

    Returns: 10

  8. 2

    10

    20

    Returns: 11

  9. 123

    456

    78910

    Returns: 642

  10. 999

    5

    999999

    Returns: 1251

  11. 685

    755

    621373

    Returns: 908

  12. 712

    156

    712174

    Returns: 1006

  13. 868

    271

    8159

    Returns: 9

  14. 404

    189

    676622

    Returns: 1682

  15. 741

    332

    132952

    Returns: 179

  16. 577

    468

    198525

    Returns: 344

  17. 600

    80

    944364

    Returns: 1592

  18. 688

    484

    133422

    Returns: 193

  19. 551

    952

    676707

    Returns: 1229

  20. 744

    485

    734324

    Returns: 988

  21. 213

    476

    454554

    Returns: 2138

  22. 419

    447

    207698

    Returns: 496

  23. 744

    64

    979058

    Returns: 1335

  24. 569

    516

    891727

    Returns: 1570

  25. 496

    221

    985996

    Returns: 1996

  26. 77

    633

    553101

    Returns: 7194

  27. 990

    187

    500321

    Returns: 507

  28. 604

    979

    77087

    Returns: 127

  29. 223

    455

    714141

    Returns: 3209

  30. 228

    213

    709601

    Returns: 3126

  31. 458

    684

    721301

    Returns: 1576

  32. 809

    719

    915143

    Returns: 1132

  33. 613

    734

    178638

    Returns: 291

  34. 624

    874

    921185

    Returns: 1477

  35. 88

    75

    934616

    Returns: 10763

  36. 971

    697

    68097

    Returns: 70

  37. 789

    539

    396449

    Returns: 502

  38. 924

    522

    842907

    Returns: 913

  39. 711

    68

    611475

    Returns: 872

  40. 984

    137

    490482

    Returns: 501

  41. 60

    463

    781983

    Returns: 13061

  42. 596

    645

    872531

    Returns: 1465

  43. 555

    367

    614805

    Returns: 1110

  44. 953

    388

    692496

    Returns: 727

  45. 519

    194

    345759

    Returns: 669

  46. 397

    184

    179109

    Returns: 453

  47. 142

    675

    461579

    Returns: 3254

  48. 539

    472

    713431

    Returns: 1325

  49. 557

    726

    265029

    Returns: 475

  50. 998

    207

    338455

    Returns: 340

  51. 843

    134

    627350

    Returns: 749

  52. 974

    357

    380604

    Returns: 391

  53. 642

    350

    567893

    Returns: 886

  54. 336

    34

    780967

    Returns: 2394

  55. 477

    689

    388631

    Returns: 815

  56. 646

    730

    514749

    Returns: 797

  57. 509

    894

    115573

    Returns: 227

  58. 351

    870

    857357

    Returns: 2444

  59. 594

    428

    933872

    Returns: 1575

  60. 107

    527

    31284

    Returns: 292

  61. 826

    773

    371836

    Returns: 450

  62. 879

    416

    198440

    Returns: 225

  63. 580

    684

    764170

    Returns: 1318

  64. 494

    982

    320534

    Returns: 648

  65. 506

    19

    280727

    Returns: 584

  66. 945

    241

    623034

    Returns: 661

  67. 504

    75

    671690

    Returns: 1349

  68. 529

    934

    6957

    Returns: 13

  69. 501

    430

    5738

    Returns: 11

  70. 501

    968

    928190

    Returns: 1853

  71. 710

    168

    714465

    Returns: 1012

  72. 7

    391

    811625

    Returns: 116243

  73. 521

    834

    422547

    Returns: 811

  74. 288

    426

    309281

    Returns: 1075

  75. 285

    666

    21477

    Returns: 75

  76. 247

    173

    722888

    Returns: 2943

  77. 742

    182

    569082

    Returns: 770

  78. 875

    598

    114427

    Returns: 130

  79. 414

    81

    938814

    Returns: 2295

  80. 329

    73

    452262

    Returns: 1393

  81. 553

    98

    455319

    Returns: 831

  82. 482

    180

    317325

    Returns: 661

  83. 567

    728

    682846

    Returns: 1205

  84. 109

    435

    473846

    Returns: 4357

  85. 78

    667

    450560

    Returns: 5784

  86. 749

    785

    225043

    Returns: 300

  87. 601

    532

    111897

    Returns: 186

  88. 592

    944

    376593

    Returns: 636

  89. 272

    654

    762012

    Returns: 2805

  90. 253

    889

    816233

    Returns: 3229

  91. 174

    352

    646839

    Returns: 3727

  92. 873

    773

    392035

    Returns: 449

  93. 194

    386

    678251

    Returns: 3505

  94. 972

    457

    455190

    Returns: 469

  95. 215

    651

    56824

    Returns: 264

  96. 577

    151

    529657

    Returns: 923

  97. 357

    895

    911979

    Returns: 2556

  98. 344

    807

    214749

    Returns: 624

  99. 20

    640

    27172

    Returns: 1360

  100. 356

    892

    74970

    Returns: 210

  101. 1

    4

    10

    Returns: 13

  102. 1

    3

    8

    Returns: 11


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: