2 solutions

  • 1
    @ 2026-10-25 15:44:17
    #include<bits/stdc++.h>
    using namespace std;
    const int N=33333;
    int m[N];
    int main(){
        long long n;
        cin>>n;
        for(int i=2;i<=n;i++){
            if(m[i]==0){
                for(int j=i*2;j<=n;j+=i) m[j]=1;
            }
        }
        	for(int i=2;i<=n;i++){
    		if(m[i]==0) cout<<i<<" ";
    	}
    return 0;
    }
    
    • @ 2026-10-25 15:44:42
      我没有抄袭!!!!!!!!!!!
    • @ 2026-10-25 15:45:15

      不信看代码!!

  • 0
    @ 2026-2-6 14:49:54
    #include<bits/stdc++.h>
    using namespace std;
    const int N=31000; //数组大小 
    int a[N];
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=2;i<=n;i++) //从前往后看每个位置 
    	{
    		if(a[i]==0) //当前位置没有被标记 
    		{
    			for(int j=2*i;j<=n;j+=i) //标记i的倍数 
    			{
    				a[j]=1;
    			}
    		}
    	}
    	for(int i=2;i<=n;i++)
    	{
    		if(a[i]==0) //i没有被标记过 
    		{
    			cout<<i<<" ";
    		}
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    62
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    195
    Accepted
    84
    Uploaded By