Cod sursa(job #2450830)

Utilizator r00t_Roman Remus r00t_ Data 24 august 2019 17:35:34
Problema Fractii Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <string>

using namespace std;

ifstream fin("fractii.in");
ofstream fout("fractii.out");

double phi(int n)
{
	double rez = n;
	for (int i = 2; i*i <= n; i++)
	{
		if (n%i == 0) {
			while (n%i == 0) n /= i;
			rez = rez * (1.0 - (1.0 / (double)i));
		}
	}
	if (n > 1)
		rez = rez * (1.0 - (1.0 / (double)n));

	return rez;
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	long long total = 0;
	fin >> n;
	total = 0;
	for (int i = 1; i <= n; i++)
		total += round(phi(i));
	fout << total*2 - 1;
}