Cod sursa(job #2023003)
Utilizator | Groza Iulia Diana Groza_Iulia_Diana | Data | 17 septembrie 2017 22:14:51 |
---|---|---|---|
Problema | Sum | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream fin("sum.in");
ofstream fout("sum.out");
int phi[100005];
long long n, x;
int main()
{
fin >> n;
for(int i=2; i<=100000; i++)
phi[i] = i;
for(int i=2; i<=100000; i+=2)
phi[i] = phi[i]/2;
for(int i=3; i<=100000; i+=2)
if(phi[i]==i)
for(int j=i; j<=100000; j+=i)
phi[j] = phi[j]/i*(i-1);
while(n--)
{
fin >> x;
fout << 2*x*phi[x] << "\n";
}
fin.close();
fout.close();
return 0;
}