Cod sursa(job #1797584)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 4 noiembrie 2016 16:52:41
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <numeric>
using namespace std;

ifstream in ( "sum.in"  );
ofstream out( "sum.out" );

const int DIM = 1e5 + 5;

int phi[DIM];

int main( int argc, const char *argv[] ) {
    ios::sync_with_stdio( false );

    iota( phi + 1, phi + DIM, 1 );
    for( int i = 2; i < DIM; i ++ ) {
        if( phi[i] != i ) {
            continue; }
        for( int j = i; j < DIM; j += i ) {
            phi[j] = ( phi[j] / i ) * (i - 1); } }

    int n; in >> n;
    for( int i = 1; i <= n; i ++ ) {
        int x; in >> x;
        out << 2LL * x * phi[x] << "\n"; }

    return 0; }