Cod sursa(job #2530230)

Utilizator rares404AlShaytan - Balasescu Rares rares404 Data 24 ianuarie 2020 15:53:05
Problema Sum Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.84 kb
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma unroll

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

#define TURBO std::ios::sync_with_stdio(false)
#define SURE_TURBO std::cin.tie(0) ; std::cout.tie(0)

#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#define FOR(x, l, r) for(int x = l ; x <= r ; ++ x)
#define FORB(x, l, r) for(int x = r ; x >= l ; -- x)
#define FOR_PAS(x, l, r, p) for (int x = l ; x <= r ; x += p)
#define debug(x) std::cerr << (#x) << " : " << x << '\n'
#define NW std::cerr << '\n'

using i64 = long long ;

typedef std::pair<int, int> PII ;
typedef std::vector<int> VI ;
typedef std::pair<PII, int> PPII ;
typedef std::vector<PII> VPI ;

#define CONSOLE 0

void R (int &x) {
#if CONSOLE == 1
        std::cin >> x ;
#elif CONSOLE == 0
        fscanf (in, "%d", &x) ;
#elif CONSOLE == 2
        fin >> x ;
#endif
}
void R (i64 &x) {
#if CONSOLE == 1
        std::cin >> x ;
#elif CONSOLE == 0
        fscanf (in, "%lld", &x) ;
#elif CONSOLE == 2
        fin >> x ;
#endif
}
void write (int x) {
#if CONSOLE == 1
        std::cout << x ;
#elif CONSOLE == 0
        fprintf (out, "%d", x) ;
#elif CONSOLE == 2
        fout << x ;
#endif
}

void writeNL () {
#if CONSOLE == 1
        std::cout << '\n' ;
#elif CONSOLE == 0
        fprintf (out, "\n") ;
#elif CONSOLE == 2
        fout << '\n' ;
#endif
}

void R (char &x) {
#if CONSOLE == 1
        std::cin >> x ;
#elif CONSOLE == 0
        x = fgetc (in) ;
#elif CONSOLE == 2
        fin >> x ;
#endif
}

template <typename T>
T Max (T a, T b, T c = 0, T d = 0, T e = 0) {return MAX (a, MAX (b, MAX (c, MAX (d, e)))) ;}
template <typename T>
T Min (T a, T b, T c = 1e9, T d = 1e9, T e = 1e9) { return MIN (a, MIN (b, MIN (c, MIN (d, e)))) ; }
template <typename T>
void WriteN (T x) { std::cerr << x << '\n' ; }
template <typename T>
void Write (T x) { std::cerr << x ; }
template <typename T>
void WriteS (T x) { std::cerr << x << ' ' ; }

const int MV = 1e5 ;

int totient[MV + 5] ;
bool sieve[MV + 5] ;

void ciur() {
        for (int i = 1 ; i <= MV ; ++ i) {
                totient[i] = i ;
        }
        for (int i = 2 ; i <= MV ; ++ i) {
                if (!sieve[i]) {
                        totient[i] = i - 1 ;
                        for (int j = i + i ; j <= MV ; j += i) {
                                sieve[j] = 1 ;
                                totient[j] = totient[j] / i  * (i - 1) ;
                        }
                }
        }
}

int main() {
        int N ;
        R(N) ;
        ciur() ;
        FOR(i, 1, N) {
                int x ; R(x) ;
                write(totient[x] * 2 * x) ; writeNL() ;
        }
}