Apple and Day Solution

Problem

You have N Apples.You can eat K apples on a single day.What's the minimum number of days required to eat all apples?

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers N, K.

Output Format

For each test case, print a single line containing one integer - the minimum number of days required to eat all apples.

Constraints

  • 1 \leq T \leq 10^4
  • 1 \leq N \leq 10^2
  • 1 \leq K \leq 10^2

Sample 1:

Input
Output
3
3 3
3 2
1
2

Explanation:

Test case 1: Since K = 3 and N = 3,it requires only 1 day to eat all apples.

Test case 2: We have K = 2 and N = 3 \gt K, it require a minimum of 2 days to eat all apples.





Program :

 import java.util.*;

class Main

{

  public static void main (String[] args)

 {

    int t,i,a,b,c,d;

    Scanner es=new Scanner(System.in);

    t=es.nextInt();

    for(i=0;i<t;i++)

    {

    a=es.nextInt();

    b=es.nextInt();

    if(a==b)

    {

    System.out.println("1");

    }

    else if(a%b==0)

    {

    d=a/b;

    System.out.println(d);

    }

    else if(a%b!=0)

    {

    d=a/b+1;

    System.out.println(d);

    }

    }

 }

}

Post a Comment

0 Comments