Cod sursa(job #1387175)

Utilizator teoceltareconstantin teodor teoceltare Data 13 martie 2015 19:52:37
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include<fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n,v[2000010];
long long s;
void citire()
{
    fin>>n;
}
void fct()
{
    int x;
    for(int a1=2;a1<=n;a1++)
    {
        if(v[a1]==0)
        {
            s++;
            x=a1*a1;
            while(x<=n)
            {
                v[x]=1;
                x+=a1;
            }
        }
    }
}
int main()
{
    citire();
    fct();
    fout<<s;
}