Cod sursa(job #2868266)

Utilizator mariog901Grigore Mario mariog901 Data 10 martie 2022 20:28:12
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 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 s = 0, aux = 0;
	if (a < b) {
		aux = a;
		a = b;
		b = aux;
	}
	while (divizor <= b) {
		if ((a % divizor == 0) && (b % divizor == 0)) {
			s = divizor;
		}
		divizor++;
	}
	if (s == 0) {
		return 1;
	}
	else {
		return 0;
	}
}
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 = s;
			}
			else {
				s++;
			}
		}
	}
	return s;
}
int main() {
	int n;
	fin >> n;
	if (n > 0) {
		fout << fractii(n);
	}
}