Cod sursa(job #1058666)

Utilizator clau05Claudiu Avram clau05 Data 15 decembrie 2013 19:20:55
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
//#define TEST

#ifdef TEST
#include <iostream>
#include <Windows.h>
#endif
#include <fstream>
using namespace std;

int cmmdc(int a, int b);
double get_time();

int main() {
	double start_time = get_time();

	int max, count = 0;

	ifstream in("fractii.in");
	in >> max;
	in.close();

	for(int i = 1; i <= max; i++) {
		for(int j = 1; j <= max; j++) {
			if(i == 1 || j == 1 || cmmdc(i, j) == 1) {
				//cout << i << '/' << j << "  ";
				count++;
			}
		}
	}

	ofstream out("fractii.out");
	out << count;
	out.close();
#ifdef TEST
	cout << endl << "Total time of execution: " << get_time() - start_time;
#endif
}

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

double get_time() {
#ifdef TEST
    LARGE_INTEGER t, f;
    QueryPerformanceCounter(&t);
    QueryPerformanceFrequency(&f);
    return (double)t.QuadPart/(double)f.QuadPart;
#else 
	return 0;
#endif
}