Pagini recente » Cod sursa (job #1887710) | Cod sursa (job #2677264) | Cod sursa (job #1012637) | Cod sursa (job #503201) | Cod sursa (job #1464404)
// 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;
}