Cod sursa(job #2829025)

Utilizator lorena_veresVeres Lorena lorena_veres Data 8 ianuarie 2022 11:05:57
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 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 <iostream>
#include<fstream>
 
using namespace std;
bool ciur[2000000];
 
int main()
{
    ifstream fin("ciur.in");
    ofstream fout("ciur.out");
    int x,cnt=0,i,j;
    fin>>x;
    ciur[0]=ciur[1]=1;
    for(i=2;i<=x;i++)
   {
    if(ciur[i]!=1)
    {
    ciur[i]=0; cnt++;
    for(j=2;j*i<=x;j++) ciur[j*i]=1;
}
}
    fout<<cnt;
    return 0;
}