Cod sursa(job #1253523)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 1 noiembrie 2014 13:59:10
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<cstdio>

using namespace std;

FILE *fin = fopen( "sum.in" , "r" ), *fout = fopen( "sum.out" , "w" );

const int nmax = 100000;
int e[ nmax + 1 ];

void init() {
    for( int i = 2; i <= nmax; ++ i ) {
        e[ i ] = i;
    }
    for( int i = 2; i <= nmax; ++ i ) {
        if ( e[ i ] == i ) {
            for( int j = i; j <= nmax; j += i ) {
                e[ j ] = e[ j ] / i * (i - 1);
            }
        }
    }
}
int main() {
    int q, x;
    init();
    fscanf( fin, "%d", &q );
    while( q -- ) {
        fscanf( fin, "%d", &x );
        fprintf( fout, "%lld\n", (long long)2 * x * e[ x ] );
    }
    fclose( fin );
    fclose( fout );
    return 0;
}