**500000000 500004321 998244300**
**这个数据测一下**,**会超时**
by Su_xi @ 2023-10-07 21:04:33
你看看题解吧,题解给得很详尽了,用解析算法,O(1)复杂度
by leiwenjin1234 @ 2023-10-07 21:04:37
**可以去看一下正解**
[P7909 [CSP-J 2021] 分糖果](https://www.luogu.com.cn/problem/solution/P7909)
**原理其实很简单**
by Su_xi @ 2023-10-07 21:08:00
for循环循环次数太多,$R-L\le10^9$,时间复杂度明显爆炸,不可取。
这道题换个角度说就是求 $\underset{k\in\lbrack L,R\rbrack}{\max}\lbrace k\operatorname{mod}n\rbrace$,O(1)就能过。
正解代码:
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l,r;
cin>>n>>l>>r;
cout<<(l/n==r/n?r%n:n-1);
return 0;
}
```
by sunnytutu @ 2023-10-07 21:23:40
```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,l,r;
int main() {
cin>>n>>l>>r;
int m=n;
while(1){
if(m+n>l) break;
m+=n;
}
for(int i=n-1; ;i--)
if(m+i<=r){
cout<<i<<endl;
break;
}
return 0;
}
```
这样T不了
by zyh0516_lucky @ 2023-10-07 23:09:33
```cpp
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d", (b / a == c / a ? c % a : a - 1));
return 0;
}
```
这个代码码风会好一点
我的C++代码写的非常像C的代码
提交C也能过
by IlovecodingC @ 2023-10-09 10:19:06