A - Attack Editorial by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
This problem requires input, output, and a division where the fractional part is rounded up. Also, since the constraints are as large as \(10^{18}\), so you need to use a suitable type.
For positive integers \(A\) and \(B\), the value \(\frac{A}{B}\) rounded up equals \(\frac{A+B-1}{B}\) rounded down, so one can use this expression to find it. Alternatively, if \(A\) is divisible by \(B\), then the sought value is found as \(\frac{A}{B}\), and otherwise, \(\frac{A}{B} + 1\), rounded down.
If you use ceil
of a decimal type, the dobule
type in C++ does not have sufficient precision to find the correct answer, for example for Sample 3. (If you use long dobule
, this time the answer will be correct.)
Regarding the type, using a 32-bit integer type will lead to an overflow, so you need to use 64-bit integer type (like long long
).
Sample code (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b;
cin>>a>>b;
cout<<(a+b-1)/b<<endl;
}
Sample code (Python)
A, B = map(int, input().split())
print((A + B - 1) // B)
posted:
last update: