一眼丁真鉴定为:我去事0分全WA代码,哪位神犇帮帮我

P1865 A % B Problem

@[gghack_m3d](/user/895690) ```cpp if(vis[i]) { ans++; } ``` 应为 `!vis[i]`
by Greenzhe @ 2022-12-26 15:24:41


@[Greenzhe](/user/552298) 阿哲。。。。。样例都过不了了,还有我不是标记了素数吗,如果写成$!vis[i]$那不就是判断合数
by gghack_Nythix @ 2022-12-26 15:26:57


@[gghack_m3d](/user/895690) 啊您标记的是非素数啊 ```cpp vis[0] = vis[1] = true; ``` 如果还是错那就是其他问题了
by Greenzhe @ 2022-12-26 15:29:09


@[gghack_m3d](/user/895690) 筛子打错了。 ```cpp for(int j = i * i; j <= n;j += i) { vis[i] = true; //乐 } ```
by liangbowen @ 2022-12-26 15:30:34


@[liangbowen](/user/367488) ```cpp #include <bits/stdc++.h> using namespace std; #define int long long bool vis[10000005]; void prime(int n) { vis[0] = vis[1] = false; for(int i = 2;i * i <= n;i ++) { if(!vis[i]) for(int j = i * i; j <= n;j += i) { vis[j] = true; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; prime(m); for(int i = 1;i <= n;i ++) { int l,r; cin >> l >> r; if(l < 1 || r > m) { cout << "Crossing the line" << endl; } else { int ans = 0; for(int i = l;i <= r;i ++) { if(vis[i]) { ans++; } } cout << ans <<endl; } } } ```这只对了一个点
by gghack_Nythix @ 2022-12-26 15:45:20


@[gghack_m3d](/user/895690) 为啥不看一眼Greenzhe的评论,你还是 ```cpp vis[0] = vis[1] = true; ``` 就可以了。然后下面改成 ```cpp for(int i = l;i <= r;i ++) { if(!vis[i]) { ans++; } } ```
by liangbowen @ 2022-12-26 15:49:41


@[liangbowen](/user/367488) 看了,现在改成标记非素数了最慢832ms然而还是有问题,只对了一个点 ```cpp #include <bits/stdc++.h> using namespace std; #define int long long bool vis[10000005]; void prime(int n) { vis[0] = vis[1] = true; for(int i = 2;i * i <= n;i ++) { if(!vis[i]) { for(int j = i * i; j <= n;j += i) { vis[j] = true; } } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; prime(m); for(int i = 1;i <= n;i ++) { int l,r; cin >> l >> r; if(l < 1 || r > m) { cout << "Crossing the line" << endl; continue; } int ans = 0; for(int i = l;i <= r;i ++) { if(!vis[i]) { ans++; } } cout << ans <<endl; } } ```
by gghack_Nythix @ 2022-12-26 15:54:06


@[liangbowen](/user/367488) 本来想水一道题,结果还没过
by gghack_Nythix @ 2022-12-26 15:54:36


@[gghack_m3d](/user/895690) ????????我过了啊
by liangbowen @ 2022-12-26 15:55:11


@[liangbowen](/user/367488) 我说的是我
by gghack_Nythix @ 2022-12-26 15:55:50


| 下一页