Cod sursa(job #2669170)

Utilizator thinkphpAdrian Statescu thinkphp Data 6 noiembrie 2020 12:24:22
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <iostream>
#include <fstream>
#define FIN "ciur.in"
#define FOUT "ciur.out"

typedef unsigned long ulong;

namespace Math {

	namespace Eratosthenes {

              ulong getCount(ulong n) {

                    bool primes[n+1];

                    ulong count = n - 1;

                    ulong j;

                    for (ulong i = 1; i < n + 1; ++i)
                    {
                       	 primes[ i ] = true;   
                    }   


                    for (ulong i = 2; (i * i) <= n; ++i)      	
                    {
                         if( primes[ i ] ) {

                         	 j = 2; 

                         	 while((i * j) <= n) {

                                   ulong multiply = i * j;

                                   if(primes[ multiply ] == true) count--;

                                   primes[multiply] = false;

                                   j++;                         	 	
                         	 }
                         }
                    }

                return count; 
              } 

	}
}

int main() {
     
	std::ifstream fin(FIN);
	std::ofstream fout(FOUT);
	ulong n;
    fin>>n;
    fout<<Math::Eratosthenes::getCount(10); 
	return(0);
}