Official
A - Counting Editorial by en_translator
Let us split into cases as follows.
If \(A>B\)
Obviously the answer is \(0\).
If \(A \leq B\)
\((B-A+1)\) integers are between \(A\) and \(B\) (inclusive): \(A,A+1, \ldots, \) and \(B\).
Therefore, one can obtain AC with the program like this.
Sample code (Python)
A,B = map(int,input().split())
if A>B:
print(0)
else:
print(B-A+1)
Note that we can avoid using a conditional branch as follows.
Sample code (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B; cin >> A >> B;
cout << max(0,B-A+1) << endl;
}
posted:
last update: