Cod sursa(job #1917308)

Utilizator al_k_ponyClaudiu Babin al_k_pony Data 9 martie 2017 11:55:58
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
# include <bits/stdc++.h>
# define maxn 500001
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;
const int inf = INT_MAX;

bool p[2000001];
int n;
int ans;

int32_t main(){_
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);
    cin >> n;
    memset(p,1,sizeof(p));
    for(int i = 2;i<=n;i++)
        if(p[i])
        {
            ans++;
            for(int j = i * 2;j <= n;j += i) p[j] = 0;
        }
    rc(ans);
}