Cod sursa(job #1996285)

Utilizator budure95Budure Marius Stelian budure95 Data 30 iunie 2017 20:47:10
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<iostream>
#include<fstream>

using namespace std;

bool nrPrimeIntreEle(int a, int b);

int main(){
	int count = 0;
	unsigned int n;
	
	ifstream inFile;
	inFile.open("fractii.in.txt");
	ofstream outFile;
	outFile.open("fractii.out");
	
	while (!inFile.eof()){
		inFile >> n;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				if (nrPrimeIntreEle(i, j)){
					count++;
				}
			}
		}
		
		outFile << count << "\n";

		count = 0;
	}
	outFile.close();
	inFile.close();
	return 0;
}

bool nrPrimeIntreEle(int a, int b){
	while (a != b){
		if (a > b){
			a = a - b;
		}
		else{
			b = b - a;
		}
	}
	if (a == 1){
		return true;
	}
	else{
		return false;
	}
}