Cod sursa(job #2012110)

Utilizator sandupetrascoPetrasco Sandu sandupetrasco Data 17 august 2017 22:09:26
Problema Sum Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#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";
	}
}