Cod sursa(job #2477409)

Utilizator DDDECARRusu Dinu Stefan DDDECAR Data 20 octombrie 2019 12:01:30
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<fstream>
std::ifstream in("fractii.in");
std::ofstream out("fractii.out");
int n;
int total = 0;
bool primes(int i, int j);
int main() {
	in >> n;
	for (int i = 1; i*i <= n; i++)
		for (int j = 1; j*j <= n; j++) {
			if (i != j)
				if (i == 1 || j == 1) {
					total++;
				}
				else if (primes(i, j)) {
					total++;
				}
		}
	out << total * 4 + 1;
}

bool primes(int i, int j) {

	int t;
	while (j != 0) {
		t = i;
		i = j;
		j = t % j;
	}
	return i == 1;
}