Cod sursa(job #1247259)

Utilizator silidragosSilion Dragos silidragos Data 22 octombrie 2014 15:34:57
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<iostream>
#include<fstream>

using namespace std;

bool V[2000001];

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

	int N;
	int nr = 0;
	f >> N;

	for (int i = 2; i <= N; ++i){
		int j = i;
		if (V[j] != true){
			nr++;
			while (j <= N){
				V[j] = true;
				j += i;
			}
		}

	}
	g << nr << '\n';

	f.close();
	g.close();
	return 0;
}