Cod sursa(job #2619375)

Utilizator robyrobtRobert Pomohaci robyrobt Data 27 mai 2020 16:11:37
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>

std::ifstream fin("fractii.in");
std::ofstream fout("fractii.out");

int cmmdc(int a, int b) {
	while (a != b) {
		if (a > b) {
			a = a - b;
		}
		else {
			b = b - a;
		}
	}
	if (a == 1 || b == 1) {
		return 0;
	}
	return a;
}

//std::cout << cmmdc(4, 6);

int main()
{
	int n, k = 0;
	fin >> n;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if ((i % j == 0 && j != 1) || (j % i == 0 && i != 1) || cmmdc(i,j) != 0) {
				k++;
			}
		}
	}
	fout << n * n - k;
}