萌新求助,为什么我的代码L超过3就会RE?

P5723 【深基4.例13】质数口袋

stO xlz Orz
by 出言不逊王子 @ 2020-06-25 09:22:36


数组越界了
by t162 @ 2020-06-25 09:24:28


Orz 楼上的和lz
by Callous_Murder @ 2020-06-25 09:30:26


Orz 楼上、楼上的楼上和lz
by impuk @ 2020-06-25 09:35:59


把数组开到外面吧(宝铃过来人的忠告
by 夜枭只会舔fufu @ 2020-06-25 09:51:31


没注释差评(
by mesan @ 2020-06-25 09:54:47


@[小梨子](/user/303977) `int a[l]` 表示能访问的区间为 $0 \leqslant x < l$,不能访问 `a[l]`
by Mitama @ 2020-06-25 10:04:55


@[小梨子](/user/303977) 循环c的那里您打的是i++
by IceYukino @ 2020-06-25 10:17:28


```cpp #include <iostream> #include <cstdio> using namespace std; int a[1000000],s[1000000],cnt,l,he; int main(){ scanf("%d",&l); a[0]=1;a[1]=1; for(int i=2;i<=10000;i++) if(a[i]==0){ s[++cnt]=i; for(int c=2;c<=10000/i;c++) a[i*c]=1; } cnt=0; while(he<=l-s[cnt+1]){ he+=s[++cnt]; cout<<s[cnt]<<endl; } cout<<cnt<<endl; return 0; } ``` 略改了一下,A了(因为真看不懂lz写的什么。。。。。。,直接筛一下+while不就行了吗(wtcl看不懂
by IceYukino @ 2020-06-25 10:25:03


@[出言不逊王子](/user/336603) 不不不我很菜的
by 屑梨子 @ 2020-06-25 10:25:53


| 下一页