Pagini recente » Cod sursa (job #502544) | Cod sursa (job #3004974) | Cod sursa (job #2758429) | Borderou de evaluare (job #367025) | Cod sursa (job #2536655)
#include <iostream>
#include <fstream>
#define N 100005
using namespace std;
ifstream fin("sum.in");
ofstream fout("sum.out");
/*6 -> 0..10
1 5 7 11
6 = 2 * 3
ind(6) = 6 * (1 -1/2)(1-1/3)
p + d = x => x + d
q(1) = {1, 5} = ind(6)
q(2) = {2, 4} = ind(3)
q(3) = {3} = ind(2)
q(4) = O
q(5) = O
q(6) = {6} = ind(1)
q(1) = 6 - q(2) - q(3) - q(4) - q(5) - q(6)
6 = ind(1) + ind(2) + ind (3) + ind(6)
ind(6) = 6 - (ind(1) + ind(2) + ind (3)) */
int ind[N];
void precalculare()
{
int i,j;
for(i=1;i<=N;++i)
ind[i]=i;
for(i=1;i<=N;++i)
for(j=2*i;j<=N;j=j+i)
ind[j]-=ind[i];
}
int main()
{
int i,x,n;
fin>>n;
precalculare();
for(i=1;i<=n;++i)
{
fin>>x;
fout<<2*x*ind[x]<<"\n";
}
return 0;
}