Cod sursa(job #2513122)
Utilizator | Data | 22 decembrie 2019 13:54:49 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int n,nr,v[2000001];
bool prim(int n)
{if(n<2)
return 0;
if(n==2)
return 1;
for(int i=2; i*i<=n;i++)
if(n%i==0)
return 0;
return 1;
}
int main()
{f>>n;
for(int i=2;i<=n;i++)
{
if(prim(i)==1)
{
nr++;
}
}
g<<nr;
return 0;
}