Pagini recente » Cod sursa (job #2160705) | Istoria paginii runda/concurss | Cod sursa (job #231641) | Cod sursa (job #2021841) | Cod sursa (job #2012110)
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define oo 1000000000
#define PII pair <int, int>
using namespace std;
int n, tab[200100];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
ifstream cin("sum.in");
ofstream cout("sum.out");
cin >> n;
for (int i = 1; i <= 100000; i++) tab[i] = i - 1;
for (int i = 2; i <= 100000; i++)
for (int j = i + i; j <= 100000; j += i)
tab[j] -= tab[i];
auto pr = [&](ll x){
for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return 0;
return 1;
};
while (n--){
ll x;
cin >> x;
if (pr(x)) cout << 2 * x * (x - 1) << '\n';
else cout << 2 * x * tab[x] << "\n";
}
}