Cod sursa(job #1024610)

Utilizator alabala1vali smerica alabala1 Data 8 noiembrie 2013 20:57:24
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#include <cmath>
bool cmmdc(unsigned i, unsigned j)
{
	if (i && j)
		return cmmdc(j, i%j);
	return j == 1 || i == 1;
}
unsigned euleri(unsigned y, unsigned u)
{
	if (y == 1 || u == 1)
		return 1;
	return cmmdc(y, u) + euleri(y, u - 1);
}
unsigned eulerp(unsigned y, unsigned u)
{
	if (!u || u == 1)
		return 1;
	return cmmdc(y, u) + eulerp(y, u - 2);
}
int main()
{
	unsigned n, x = 0;
	std::ifstream f("fractii.in");
	std::ofstream g("fractii.out");
	f >> n;
	f.close();
	for (unsigned i = 1; i <= n;i+=2)
	    x += euleri(i, i - 1) + eulerp(i + 1, i);
	if (x % 2)
		x += euleri(x, x - 1);
	g << x * 2 - 1;
	g.close();
}