Cod sursa(job #2210850)

Utilizator andreiivan05Ivan Andrei andreiivan05 Data 8 iunie 2018 11:45:05
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//


#include <iostream>
#include <fstream>

using namespace std;

ifstream f("fractii.in");
ofstream g("fractii.out");
int cmmdc(int x, int y)
{
	while (x != y)
	{
		if (x > y)
			x = x - y;
		else
			y = y - x;
	}
	return x;
}

int main()
{
	int p, q, n, nr=0;
	f >> n;
	for (p = 1;p <= n;p++)
	{
		for (q = 1;q <= n;q++)
		{
			if (cmmdc(p, q) == 1)
				nr++;
		}
	}
	g << nr;
    return 0;
}