Cod sursa(job #516866)
Utilizator | Data | 26 decembrie 2010 19:43:25 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
// Sieve of Eratosthenes.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
int a[20000001], N, c=0;
int main () {
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &N);
for (int i = 2; i <= N; ++i) {
if (!a[i]) {
++c;
for (int j = i*2; j < N; j+=i) {
a[j]=1;
}
}
}
printf("%d", c);
return 0;
}