为什么两个代码都能过
查看原帖
为什么两个代码都能过
708338
livedreamlmy楼主2022/4/15 18:37
#include<bits/stdc++.h>
using namespace std;
bool vis[100005];
int n;
void getPrime(int x){
    vis[1]=1;
    for(int i=2;i*i<=x;i++)
        if(vis[i]==false)
            for(int j=i*i;j<=x;j+=i)
                vis[j]=true;
    return;
}
int main(){
    cin>>n;
    getPrime(100000);
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x>=2&&vis[x]==0)
            cout<<x<<" ";
    }
    return 0;
}

这个代码是能过得,可为什么把第六行的

vis[1]=1;

换成

vis[1]==1;

照样能过???

2022/4/15 18:37
加载中...