Cod sursa(job #2513291)

Utilizator kokitchyAlastor kokitchy Data 22 decembrie 2019 20:06:30
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <iostream>
#include <fstream>
#include <vector>

#define NMAX 1000000

using namespace std;

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

	int n;
	fin >> n;

	long long nr = 0;
	int a[NMAX];
	for (int i = 1; i <= n; i++)
		a[i] = i - 1;

	for (int i = 2; i <= n; i++) {
		nr += a[i];
		for (int j = 2 * i; j <= n; j += i)
			a[j] -= a[i];
	}

	fout << 2 * nr + 1;

	fin.close(), fout.close();
}