Cod sursa(job #1464404)

Utilizator noomercyBarascu Alexandru Florian noomercy Data 23 iulie 2015 13:43:28
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
// Problema 003 Fractii.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>

using namespace std;

ifstream fileIn("fractii.in");
ofstream fileOut("fractii.out");

bool hasCmmdc(int a, int b)
{
	int n = a < b ? a : b;
	int i = 2;
	for (i; i <= n; i++)
		if (a%i == 0 && b% i == 0)
			return true;
	return false;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int n;
	fileIn >> n;
	int count = 0, i = 1, j;
	for (i; i <= n; i++)
		for (j = 1; j <= n; j++)
			if (j == 1 )count++;
			else
			if ( i!= j && !hasCmmdc(i,j)) count++;
	fileOut << count;
	fileIn.close();
	fileOut.close();
	return 0;
}