Cod sursa(job #1385292)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 11 martie 2015 20:49:03
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <algorithm>

#define DIM 1000005
#define infile "fractii.in"
#define outfile "fractii.out"

using namespace std;

ifstream fin(infile);
ofstream fout(outfile);

int n;

int c[1000005];

int main() {

	fin >> n;

	for (int i = 2; i <= n; ++i)
		c[i] = (1LL * i * (n - 1)) / n;

	for (int i = 2; i <= n; ++i) {

		for (int j = i + i; j <= n; j += i)
			c[j] -= c[i];

	}

	long long sol = 0;

	for (int i = 2; i <= n; ++i)
		sol += c[i];

	fout << (2 * sol) + 1 << "\n";

	return 0;
}

//Trust me, I'm the Doctor!