Given a pile of chocolates and an integer ‘k’ i.e. the number of iterations, the task is to find the number of chocolates left after k iterations.
Note: In every iteration, we can choose a pile with a maximum number of chocolates, after that square root of chocolate remains and rest is eaten.
Input: Chocolates = 100000000, Iterations = 3 Output: 10 Input: Chocolates = 200, Iterations = 2 Output: 4
Note: Output is printed after rounding off the value as in the 2nd example, the output will be around 3.76 approx.
It is given that maximum no. of chocolates are selected so consider total pile since it will be maximum.
Next, it is given that in the each iteration only square of chocolates are left so that by considering the mathematics equation of
(((number)n)n)...n for k times = (number)nk
Since here k times the square root is performed so the (1/2)k is powered with the N.
Consider the example of 100000000 chocolates and no. of iterations is 3 then it will be as
(((100000000)1/2)1/2)1/2 = (100000000)(1/2)3 = 10
Below is the required formula to find the remaining chocolates:
round(pow(n, (1.0/pow(2, k))))
Chocolates left after 3 iterations are 10
- Minimum and maximum number of N chocolates after distribution among K students
- Puzzle | Selling Chocolates
- Find the minimum number of rectangles left after inserting one into another
- Fill array with 1's using minimum iterations of filling neighbors
- CSS | left Property
- CSS | padding-left Property
- Left-Truncatable Prime
- CSS | margin-left Property
- CSS | border-left Property
- CSS | border-top-left-radius Property
- CSS | border-left-width Property
- CSS | border-left-color Property
- CSS | border-left-style Property
- How to distinguish left and right mouse click using jQuery?
- CSS border-bottom-left-radius Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.