Cod sursa(job #2674881)

Utilizator george347Ungureanu Octavian george347 Data 20 noiembrie 2020 17:00:58
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int N,k;
bool a[2000002];
int main()
{
    f >> N;
    k = 1;
    
    for(int i = 4; i <= N; i+=2){
        a[i] = 1;
    }
    for(int i = 3; i <= N; i+=2){
        if(a[i] == 0){
            k++; 
        for(int j = i+i; j <= N; j+=i){
            a[j] = 1;
         }
        }
    }
    g << k;
    return 0;
}