Cod sursa(job #1509031)

Utilizator antohieantohie andrei antohie Data 23 octombrie 2015 13:53:27
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int a[2000000];

int main ()
{
    ifstream f("ciur.in");
    ofstream g("ciur.out");

    int n;
    f>>n;

    int i,j;
    for(i=2; i<=n; i++)
        for(j=2; j<=n/i+1; j++)
            if(i*j<=n && a[j*i]==0)
                a[j*i]=1;
    int    k=0;
    for(i=2; i<=n; i++)
        if(a[i]==0)
            k++;
    g<<k;



}