Cod sursa(job #2147859)

Utilizator Moldo97Moldoveanu Alexandru Moldo97 Data 1 martie 2018 03:24:26
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h";
#include <fstream>
using namespace std;
int main()
{
	ifstream in("fractii.in");
	ofstream out("fractii.out");
	int i, j, n, rest, max = 0, a, b;
	in >> n;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			if (i>2 && j>2 && (i % 2 == 0) && (j % 2 == 0))
				break;
			if (j == 1)
				max = max + 1;
			else
			{
				a = i;
				b = j;
				while (b != 0)
				{
					rest = b;
					b = a % b;
					a = rest;
				}
				if (a == 1)
					max = max + 1;
			}
		}
	}
	out << max;
}