Pagini recente » Cod sursa (job #353756) | Cod sursa (job #1683591) | Cod sursa (job #846871) | Monitorul de evaluare | Cod sursa (job #1058666)
//#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
}