Problem Statement
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
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
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.
41
4
1337
Returns: 42
666
13
823172
Returns: 1337
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.
1
2
1000000
Returns: 1999999
1000
1000
1000000
Returns: 1001
2
11
20
Returns: 10
2
10
20
Returns: 11
123
456
78910
Returns: 642
999
5
999999
Returns: 1251
685
755
621373
Returns: 908
712
156
712174
Returns: 1006
868
271
8159
Returns: 9
404
189
676622
Returns: 1682
741
332
132952
Returns: 179
577
468
198525
Returns: 344
600
80
944364
Returns: 1592
688
484
133422
Returns: 193
551
952
676707
Returns: 1229
744
485
734324
Returns: 988
213
476
454554
Returns: 2138
419
447
207698
Returns: 496
744
64
979058
Returns: 1335
569
516
891727
Returns: 1570
496
221
985996
Returns: 1996
77
633
553101
Returns: 7194
990
187
500321
Returns: 507
604
979
77087
Returns: 127
223
455
714141
Returns: 3209
228
213
709601
Returns: 3126
458
684
721301
Returns: 1576
809
719
915143
Returns: 1132
613
734
178638
Returns: 291
624
874
921185
Returns: 1477
88
75
934616
Returns: 10763
971
697
68097
Returns: 70
789
539
396449
Returns: 502
924
522
842907
Returns: 913
711
68
611475
Returns: 872
984
137
490482
Returns: 501
60
463
781983
Returns: 13061
596
645
872531
Returns: 1465
555
367
614805
Returns: 1110
953
388
692496
Returns: 727
519
194
345759
Returns: 669
397
184
179109
Returns: 453
142
675
461579
Returns: 3254
539
472
713431
Returns: 1325
557
726
265029
Returns: 475
998
207
338455
Returns: 340
843
134
627350
Returns: 749
974
357
380604
Returns: 391
642
350
567893
Returns: 886
336
34
780967
Returns: 2394
477
689
388631
Returns: 815
646
730
514749
Returns: 797
509
894
115573
Returns: 227
351
870
857357
Returns: 2444
594
428
933872
Returns: 1575
107
527
31284
Returns: 292
826
773
371836
Returns: 450
879
416
198440
Returns: 225
580
684
764170
Returns: 1318
494
982
320534
Returns: 648
506
19
280727
Returns: 584
945
241
623034
Returns: 661
504
75
671690
Returns: 1349
529
934
6957
Returns: 13
501
430
5738
Returns: 11
501
968
928190
Returns: 1853
710
168
714465
Returns: 1012
7
391
811625
Returns: 116243
521
834
422547
Returns: 811
288
426
309281
Returns: 1075
285
666
21477
Returns: 75
247
173
722888
Returns: 2943
742
182
569082
Returns: 770
875
598
114427
Returns: 130
414
81
938814
Returns: 2295
329
73
452262
Returns: 1393
553
98
455319
Returns: 831
482
180
317325
Returns: 661
567
728
682846
Returns: 1205
109
435
473846
Returns: 4357
78
667
450560
Returns: 5784
749
785
225043
Returns: 300
601
532
111897
Returns: 186
592
944
376593
Returns: 636
272
654
762012
Returns: 2805
253
889
816233
Returns: 3229
174
352
646839
Returns: 3727
873
773
392035
Returns: 449
194
386
678251
Returns: 3505
972
457
455190
Returns: 469
215
651
56824
Returns: 264
577
151
529657
Returns: 923
357
895
911979
Returns: 2556
344
807
214749
Returns: 624
20
640
27172
Returns: 1360
356
892
74970
Returns: 210
1
4
10
Returns: 13
1
3
8
Returns: 11