Cod sursa(job #2271391)

Utilizator ClaudiuTClaudiu Timofte ClaudiuT Data 28 octombrie 2018 15:06:38
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std ;

ifstream fin("fractii.in") ;
ofstream fout("fractii.out") ;

int N ;
bool Nr_Prime[1000001] ;

void Eratostene(bool Nr_Prime[])
{
    for(int i = 2 ; i * i <= N ; i += 1)
        if(!Nr_Prime[i])
            for(int j = 2 ; j <= N / i ; j += 1)
                Nr_Prime[i * j] = true ;
}

float Euler(int x)
{
    float nr = x ;

    for(int i = 2 ; i <= x ; i += 1)
    {
        if(!(Nr_Prime[i]) && !(x % i))
            nr *= (1.0 - 1.0 / i) ;
    }

    return nr ;
}

void Function()
{
    Eratostene(Nr_Prime) ;

    int nr = 0 ;

    for(int i = 2 ; i <= N ; i += 1)
    {
        nr += 2 * Euler(i) ;
    }

    fout << nr + 1 ;

}

int main()
{
    ios_base::sync_with_stdio(false) ;
    fin.tie(NULL) ;

    fin >> N ;

    Function() ;


    return 0 ;
}