0分求助

P1865 A % B Problem

```cpp for(int i=l;i<=r;i++)if(f(i))ans++; ``` 和外层的i重名了
by Frost2008 @ 2022-03-01 21:06:09


另:没有特判0和1和负数
by Frost2008 @ 2022-03-01 21:07:23


**** _还是错了_ **** ``` #include<bits/stdc++.h> using namespace std; bool f(int x) { if(x==1)return false; for(int i=2;i<sqrt(x);i++) if(x%i==0) return false; return true; } int main() { int l,r,n,m; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>l>>r; if(l<0&&r>=m) { cout<<"Crossing the line"<<endl; continue; } int ans=0; for(int j=l;j<=r;j++)if(f(j))ans++; cout<<ans<<endl; } return 0; } ``` [链接](https://www.luogu.com.cn/record/70371056)
by hhb0422 @ 2022-03-01 21:13:48


l<1||r>m
by Frost2008 @ 2022-03-01 21:15:36


不用筛法也会超时的吧
by LeslieKang @ 2022-03-09 14:52:40


@[Yuki_S2008](/user/495053) l<1||l>m||r<1||r>m
by inkpigeon @ 2022-07-17 17:10:13


@[hhb0422](/user/543760) 换成线性筛(欧拉筛)
by inkpigeon @ 2022-07-17 17:11:07


|