Cod sursa(job #1929801)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 18 martie 2017 10:25:47
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

const int N = 1000100 ;

int phi[ N ];
long long sol ;
int n ;

void CalculatePhi(  ){
    static int i , j;


    phi [ 1 ] = 1 ;
    for ( i = 2 ; i <= n ; i++ ){
        phi [ i ] = i - 1 ;
    }

    for ( i = 2 ; i <= n ; i++ ){
        sol += 2 * phi [ i ];
        for ( j = 2 * i ; j <= n ; j += i ){
            phi [ j ] -= phi [ i ] ;
        }
    }

}

int main(){

    freopen("fractii.in","r",stdin);
    freopen("fractii.out","w",stdout);


    scanf("%d",&n);

    CalculatePhi( );

    printf("%lld",sol + 1 );


    return 0;
}