Cod sursa(job #120540)
Utilizator | Data | 5 ianuarie 2008 20:32:14 | |
---|---|---|---|
Problema | Sum | Scor | 5 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream.h>
using namespace std;
long long u[100005],tot[100005];
void totient()
{
long i,j;
for (i=2;i<=100001;i++)
tot[i]=i;
for (i=2;i<=100001;i++)
{
if (u[i]==0)
{
j=2;
while(i*j<=100001)
{
u[i*j]=1;
tot[i*j]=tot[i*j]-(tot[i*j]/i);
j++;
} }
}
}
int main()
{ long long n,sol,x,i;
ifstream f1("sum.in");
ofstream f2("sum.out");
f1>>n;
totient();
for (i=1;i<=n;i++)
{
f1>>x;
sol=2*x*tot[x];
f2<<sol<<"\n";
}
return 0;
}