Cod sursa(job #1390075)
| Utilizator | Data | 16 martie 2015 20:40:38 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
// ciur.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
bool prim[2000001] ;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
long n=0;
f >> n;
long k = 0;
for (int i = 2; i <= n; i++) prim[i] = 1;
for (int i = 2; i <= n; i++)
{
if (prim[i]==1)
{
k++;
for (int j = 2; j <= n; j++)
{
prim[i*j] = 0;
}
}
}
g << k;
f.close();
g.close();
return 0;
}
