Run for Fun
Source: codechef
Difficulty: 375

Run for Fun
Chef is participating in a race of$Y$kilometers. However, Chef gets tired and needs to take a rest after every$X$kilometers.
Can you determine how many times Chef will stop to rest before reaching the finish line?
Input Format
The only line of input contains two space-separated integers$X$and$Y$— the number of kilometers Chef can run before needing a rest, and the total distance of the race in kilometers.
Output Format
Print a single integer — the number of times Chef will stop to rest before completing the race.
Constraints$1 \leq X,Y \leq 10$Sample 1:
Explanation:
After running the first kilometer, Chef gets tired and stops to rest. After resting, he completes the remaining kilometer to finish the race. Since he stops only once before reaching the finish line, the answer is$1$.
Sample 2:
Input
Output
2 5
2
Explanation:
After running the first$2$kilometers, Chef gets tired and takes a rest. He then runs another$2$kilometers and rests again. Finally, he completes the remaining$1$kilometer to finish the race. Since he stops twice before reaching the finish line, the answer is$2$.
Sample 3:
Input
Output
3 3
0
Explanation:
After running the first$3$kilometers, he reaches the finish line without needing to rest.
Sample 4:
Input
Output
4 3
0
Explanation:
Since the total distance is less than the resting limit, Chef reaches the finish line without stopping.

Sample Input:
1 2

Sample Output:
1

C++ solution:
#include <bits/stdc++.h>
using namespace std;

int main() {
    // your code goes here
    int x,y;
    cin>>x>>y;
    if(x==y){
        cout<<0<<endl;
    }
    else if(y%x==0){
        cout<<(y/x -1)<<endl;
    }
    else{
        cout<<y/x<<endl;
    }
}

Go solution:
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

func main() {
        reader := bufio.NewReader(os.Stdin)
        scanner := bufio.NewScanner(reader)
        scanner.Split(bufio.ScanLines)

        scanner.Scan()
        line := scanner.Text()
        parts := strings.Split(line, " ")

        x, _ := strconv.Atoi(parts[0])
        y, _ := strconv.Atoi(parts[1])

        if x == y {
                fmt.Println(0)
        } else if y%x == 0 {
                fmt.Println(y/x - 1)
        } else {
                fmt.Println(y / x)
        }
}

Java solution:
import java.util.Scanner;
class RunForFun {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int X = sc.nextInt(); // Distance Chef can run before resting
        int Y = sc.nextInt(); // Total race distance
        
        int restStops = (Y - 1) / X;
        
        System.out.println(restStops);
        
        sc.close();
    }
}

JavaScript solution:
// your code goes here
let stdInput = "";
process.stdin.on("data", input => stdInput += input);
process.stdin.on("end", ()=>{
    const [x, y] = stdInput.trim().split(" ").map(Number);
    const result = Math.ceil(y/x) - 1;
    
    console.log(result);
});

Python solution:
# cook your dish here
def chef(x,y):
   if y <= x:
       z = 0
   else:
       z = (y - 1)//x
   print(z)
    
        
    
x,y = map(int,input().split())
chef(x,y)

Ruby solution:
# Read input safely and handle potential errors
begin
  input = gets
  if input.nil? || input.strip.empty?
    puts 0
    exit
  end

  x, y = input.strip.split.map(&:to_i)

  if y <= x
    puts 0
  else
    puts (y - 1) / x
  end
rescue
  puts 0
end