Editorial
Algorithm Analysis
The maximum number of rabbits that will guaranteed to be in one cage equals . This expression can be calculated as: . The given expression in C language can also be written as: The result of the type conversion operation bool(x)
is:
0 (false), if ;
1 (true), if ;
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)