Cod sursa(job #2180684)

Utilizator rotarraresRotar Rares rotarrares Data 21 martie 2018 01:28:47
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cmath>
using namespace std;
int n = 4;
int answer = 1;
bool k[2000000];
int main()
{
    cin >> n;
    short i = 0;
    short j = 0;
    for(i=2;i<=sqrt(n);i++){
        if(k[i]==false){
            for(j=2;j<=n/i;j++){
                if(k[i*j]==false){
                    k[i*j]=true;
                    answer++;
                }
            }
        }
    }
    answer = n - answer;
    cout<<answer;
    
    return 0;
}