Cod sursa(job #2083402)

Utilizator KernelovicNegrean Victor Kernelovic Data 7 decembrie 2017 17:55:57
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
 
using namespace std;
  
//multiple = 1, prime = 0
  
bool sir[2000001];
  
int main()
{
    ifstream inf("ciur.in");
    ofstream outf("ciur.out");
  
    int n; inf >> n;
    int s = 0;
  
    for(int i = 2; i <= n; i++)
    {
        if(sir[i]) continue;
  
        for(int j = i * 2; j <= n; j += i)
        {
            sir[j] = true;
        }
    }
  
    for(int i = 2; i <= n; i++)
    {
        if(sir[i] == false)
        {
            s += 1;
        }
    }
    outf << s;
}