Pagini recente » Cod sursa (job #1720486) | Cod sursa (job #1619223) | Cod sursa (job #1390400) | Cod sursa (job #2148312) | Cod sursa (job #664424)
Cod sursa(job #664424)
// http://infoarena.ro/problema/ciur
#include <fstream>
using namespace std;
const int MAXSIZE = 2000001;
ifstream in("ciur.in");
ofstream out("ciur.out");
int length;
bool numbers[MAXSIZE];
void eratosthenes();
int main()
{
in >> length;
in.close();
eratosthenes();
int count = 0;
for(int i=3;i<=length;i+=2)
if(!numbers[i])
count++;
out << ++count << "\n";
out.close();
return (0);
}
void eratosthenes()
{
for(int i=3;i<=length;i+=2)
for(int k=i+i;k<=length;k=k+i)
numbers[k] = true;
}