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.
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
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.