Pagini recente » Cod sursa (job #183878) | Cod sursa (job #2557981) | Cod sursa (job #2829181) | Cod sursa (job #231452) | Cod sursa (job #2330306)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("suma.in");
ofstream out("sum.out");
int phi(int n)
{
n = 2*n;
float result = n;
for (int p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result *= (1.0 - (1.0 / (float)p));
}
}
if (n > 1)
result *= (1.0 - (1.0 / (float)n));
return (int)result;
}
int main(){
int n,x,s=0;
in >> n;
for(int i = 1;i<=n;++i){
in >> x;
if( x%2==0)
out<<x*phi(x)<<'\n';
else out<<2*x*phi(x)<<'\n';
}
}