Pagini recente » Borderou de evaluare (job #2080423) | Cod sursa (job #2210849)
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#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;
}