题解 P7909 【[CSP-J 2021] 分糖果】
分类讨论。
一句话题意:求
首先画个数轴,按除以
容易看出每块中的整数
接着,如果
那么
如果
那
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n,l,r;//其实不开 LL 也行
int main(){
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
scanf("%lld%lld%lld",&n,&l,&r);
if(l/n!=r/n) printf("%lld\n",n-1);
else printf("%lld\n",r%n);
return 0;
}