Cod sursa(job #2450828)

Utilizator r00t_Roman Remus r00t_ Data 24 august 2019 17:28:45
Problema Fractii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 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()
{
	int n, total = 0;
	fin >> n;
	total = 0;
	for (int i = 1; i <= n; i++)
		total += round(phi(i));
	fout << total*2 - 1;
}