Cod sursa(job #2271109)

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

using namespace std ;

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

float Euler(int x)
{
    float nr = x ;
    float y = x ;
    if(x % 2 == 0)
    {
        while(x % 2 == 0)
            x /= 2 ;
        nr *= (1.0 - float(1.0/2)) ;
    }

    for(int d = 3 ; d <= x ; d += 2)
        if(x % d == 0)
            {
                while(x % d == 0)
                {
                    x /= d ;

                }
                float d1 = d ;
                nr *= (1.0 - 1.0/d1) ;

            }
    return nr ;


}

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

    int n ;
    fin >> n ;
    int nr = 0 ;

    for(int i = 2 ; i <= n ; i += 1)
        nr += (2 * Euler(i)) ;

    nr += 1 ;
    fout << nr ;

    return 0 ;
}