Pagini recente » Cod sursa (job #1634746) | Cod sursa (job #97675) | Cod sursa (job #2472192) | Istoria paginii runda/valicaroom2 | Cod sursa (job #664430)
Cod sursa(job #664430)
// 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()
{
int stop = length / 2;
for(int i=3;i<=length;i+=2)
if(!numbers[i])
for(int k=i;k<=length;k=k+(i << 1))
numbers[k] = true;
}