Rabbits in the cells#1610

Rabbits in the cells (Editorial)

Algorithm Analysis

The maximum number of rabbits that will guaranteed to be in one cage equals [(m + n - 1) / n]. This expression can be calculated as: [(m + n - 1) / n] = (m + n - 1) / n. The given expression in C language can also be written as: [(m + n - 1) / n] = m / n + \text{bool}(m \% n); The result of the type conversion operation bool(x) is:

Algorithm Implementation

Read the input data. Compute and output the answer.

scanf("%d %d",&n,&m);
res = (m + n - 1) / n;
printf("%d\n",res);

Algorithm Implementation – Conditional Operator

#include <stdio.h>

int n, m, res;

int main(void)
{
    scanf("%d %d", &n, &m);
    res = m / n;
    if (m % n > 0) res++;
    printf("%d\n", res);
    return 0;
}

Algorithm Implementation – bool

#include <stdio.h>

int n, m, res;

int main(void)
{
    scanf("%d %d", &n, &m);
    res = m / n + bool(m % n);
    printf("%d\n", res);
    return 0;
}

Java Implementation

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        int n = con.nextInt(), m = con.nextInt();
        int res = (m + n - 1) / n;
        System.out.println(res);
    }
}

Python Implementation

n, m = map(int,input().split())
res = (m + n - 1) // n
print(res)