Cod sursa(job #3381007)

Utilizator DobrePetruDobre Petru Daniel DobrePetru Data 3 decembrie 2026 16:43:42
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda cex_03 Marime 0.84 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
ifstream fin("sum.in");
ofstream fout("sum.out");
long long q,x;
long long phi(long long n)
{
    long long r=n,d=2,t=0;
    if(n==1) return 1;
    while(n>1&&d*d<=n)
    {
        if(n%d==0)
        {
            r=r/d*(d-1);
            while(n%d==0) {n/=d;t++;}
        }
        d++;
    }
    if(n>1) r=r/n*(n-1);
    return r;
}
signed main()
{
   fin>>q;
   while(q)
   {
       fin>>x;
       fout<<phi(x)*2*x<<'\n';
       q--;
   }
    return 0;
}