Cod sursa(job #1589412)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 3 februarie 2016 22:54:24
Problema Sum Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>
#include <array>
#include <numeric>
using namespace std;

constexpr int maxx = 100010;

int main(){
	array<long long, maxx> buf = {};
	iota(begin(buf), end(buf), -1);
	for(int i = 2; i < maxx; ++i){
		for(int j = 2*i; j < maxx; j += i){
			buf[j] -= buf[i]; } }

	ifstream f("sum.in");
	ofstream g("sum.out");
	int n;
	f >> n;

	for(long long i = 0, x; i < n; ++i){
		f >> x;
		g << 2ll * x * buf[x] << '\n'; }
	return 0; }