Mai intai trebuie sa te autentifici.

Cod sursa(job #1455326)

Utilizator petru.cehanCehan Petru petru.cehan Data 27 iunie 2015 16:11:57
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin ("ciur.in") ;
ofstream fout ("ciur.out") ;

long int n , a[2000001] ;

void Citire()
{
    fin >> n;
}
int nr = 0 ;

void CiurEratostene (int n)
{
    int i , j ;
    for ( i = 3 ; i <= n ; i += 2 )
            a[i] = 1 ;
    for( i = 3 ; i <= n ; i += 2 )
        if ( a[i] == 1 )
           for ( j = i << 2 ; j <= n ; j += i )
                   a[j]=0;
    cout << 2 << " ";
    a[2] = 1 ;
    for ( i=3 ; i <= n ; i += 2 )
       if ( a[i] == 1 )
           cout << i << " " , ++ nr ;
    fout<<nr ;
}
int main()
{
    Citire();
    CiurEratostene(n);
    return 0;
}