Cod sursa(job #2180686)

Utilizator rotarraresRotar Rares rotarrares Data 21 martie 2018 01:33:43
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 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 <fstream>
#include <cmath>
using namespace std;
int n = 4;
int answer = 1;
bool k[2000000];
int main()
{
    ifstream myinput;
    ofstream myoutput;
    myinput.open("ciur.in");
    myinput >> n;
    myinput.close();
    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;
    myoutput.open("ciur.out");
    myoutput<<answer;
    myoutput.close();
    return 0;
}