3 solutions

  • -4
    @ 2024-11-30 9:45:16
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        bool a[30001];
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            a[i]=true;
        }
        a[1]=false;
        for(int i=2;i<=n;i++)
        {
            if(a[i])
            {
                for(int j=i*2;j<=n;j+=i)
                {
                    a[j]=false;
                }
                cout<<i<<" ";
            }
        }
        return 0;
    }
    

    Information

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