Pagini recente » Cod sursa (job #954462) | Cod sursa (job #646910) | Cod sursa (job #2859661) | Cod sursa (job #1126077) | Cod sursa (job #1076093)
#include <fstream>
using namespace std;
bool reduce(int a, int b)
{
int m, n, r;
// m is the largest of the input numbers
m = (a > b) ? a : b;
n = (a > b) ? b : a;
r = 0;
if ((m != 0) && (n != 0)) {
do
{
r = m % n;
m = n;
// only assign n to the new remainder, if n isn't already a divisor of m
if (r != 0)
n = r;
} while ((r != 0) && ((m % n) != 0));
}
return (n != 1);
}
int main(int argc, char*argv[])
{
ifstream inp("fractii.in");
ofstream out("fractii.out");
int n;
int c = 0;
inp >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
if (!reduce(i, j))
c++;
}
out << c;
inp.close();
out.close();
return 0;
}