Cod sursa(job #2718282)

Utilizator GheorgheBBalamatiuc Gheorghe GheorgheB Data 8 martie 2021 17:16:38
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.33 kb
#include <fstream>
using namespace std;

bool a[1000000000];

ifstream fin("ciur.in");
ofstream fout("ciur.out");

int main(){
    int n, k = 0;
    fin >> n;
    a[1] = a[0] = 1;
    for(int i=1; i<=n; i++)
    	if(a[i] == 0){
    		for(int j=2; i*j<=n; j++)
    			a[i*j] = 1;
    		k ++;
    	}
    fout << k;
}