Cod sursa(job #2969608)

Utilizator TespunCovanji Stefan Tespun Data 23 ianuarie 2023 14:32:02
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int main()
{
     freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);
    int maxn;
    cin>>maxn;
    bool ciur [maxn] = {};
    ciur[0]=ciur[1]=true;
    int rs=0;
    for(int i=2;i<maxn;i++){
        if(ciur[i]==false){
            rs++;
            for(int j=i*2; j<maxn;j+=i)
            ciur[j]=true;
        }
    }
    cout<<rs;
    return 0;
}