Cod sursa(job #2868282)

Utilizator mariog901Grigore Mario mariog901 Data 10 martie 2022 20:38:37
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int cmmdc(int a, int b) {
	int divizor = 2;
	int aux = 0;
	if (a < b) {
		aux = a;
		a = b;
		b = aux;
	}
	while (divizor <= b) {
		if ((a % divizor == 0) && (b % divizor == 0)) {
			return 0;
		}
		divizor++;
	}
	
	return 1;
	
}
int fractii(int n) {
	int i, j, s = 0;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (!((i != 1 && j != 1) && (cmmdc(i, j) == 0))) {
				s++;
			}
		}
	}
	return s;
}
int main() {
	int n;
	fin >> n;
	if (n > 0) {
		fout << fractii(n);
	}
}