Cod sursa(job #2742544)

Utilizator LucaMihaiLM10Luca Ilie LucaMihaiLM10 Data 21 aprilie 2021 10:07:23
Problema Fractii Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <stdio.h>

#define MAX_N 1000000

int phi[MAX_N + 1];

int main() {
    FILE *fin, *fout;
    int n, i, j;
    long long fractii;

    fin = fopen( "fractii.in", "r" );
    fscanf( fin, "%d", &n );
    fclose( fin );

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

    fout = fopen( "fractii.out", "w" );
    fprintf( fout, "%lld", fractii * 2 + 1 );
    fclose( fout );

    return 0;
}