Cod sursa(job #1390081)
| Utilizator | Data | 16 martie 2015 20:42:39 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| 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");
int n=0;
f >> n;
int 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 = i+i; j <= n; j=j+i)
{
prim[j] = 0;
}
}
}
g << k;
f.close();
g.close();
return 0;
}
