Help me in solving WATERCOOLER2 problem

My issue

Why y % x ==0 returns y/x -1, it shouldnt be y/x?

My code

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

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

            int x = sc.nextInt();
            int y = sc.nextInt();



            if (y % x != 0) {
                System.out.println(y / x);
            }else
                System.out.println((y /x) -1);
        }
    }
}

Problem Link: WATERCOOLER2 Problem - CodeChef

Hi @elmar1989

Actually I have gone through the question you asked and I think I have some solution of your problem. Now coming to your solution

Ques → when (y%x)==0 you want it to be y/x
Ans → Now look carefully you will only get (y%x==0) when both ‘y’ and ‘x’ are same or ‘y’ is completely divisible by ‘x’. Let’s take example for that

x = 6 , y = 12
so when you divide y/x it would give you 2 and 2 months you need a water cooler now calculate the rent cost of two months would be 12 which is same as buying the water cooler.
Hence the value of renting and buying both became same(rent cost = 12 , buying cost = 12) the chef couldn’t rent.
So in order to find the maximum month for which (renting cost < buying cost) we will just subtract 1 from the number of months we get after dividing (y/x) and hence that would give us a required output of 1.

I hope you understand that. If not, you can again ask to me. I would try to help you out.

Thanks :raised_hands: