Question: JAVA CODE PLEASE You got a lot of candy from trick-or-treating this Halloween and would like to store them safely in candy jars. Each jar

JAVA CODE PLEASE

You got a lot of candy from trick-or-treating this Halloween and would like to store them safely in candy jars. Each jar can store at most C candies and you got plenty of jars. To distribute the candies, your plan is to divide the N candies in half, forming two smaller piles, then continue dividing each of the small piles in half until we get piles that can fit in the jars. Find how many jars you will need. This strategy may not give you the least number of jars. Also note that when you divide an odd number pile in half, one of them will have one more than the other.

Input Format

Two lines with integers N and C

Constraints

1 < C < N < 10,000

Output Format

Numbers of jars you end up using with the given strategy

Sample Input 0

11

3

Sample Output 0

4

Explanation 0

First you divide 11 to 5 and 6. They are still too big. Split 5 -> 2, 3 Split 6 -> 3, 3 Each of them can now fit in the given jars, so we need four.

Sample Input 1

8

1

Sample Output 1

8

Explanation 1

If each jar can store only 1, then you need 8 jars

Sample Input 2

10

2

Sample Output 2

6

Explanation 2

10

5, 5

3, 2, 3, 2

2, 1, 2, 2, 1, 2

Sample Input 0

11 3 

Sample Output 0

4

Given code for solution:

import java.io.*; import java.util.*;

public class Solution {

public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!