Cod sursa(job #2978603)

Utilizator BujorelActimelBujor Mihai Alexandru BujorelActimel Data 13 februarie 2023 22:19:30
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.6 kb
// brute force
#include <bits/stdc++.h>

using namespace std;

ifstream f("fractii.in");
ofstream g("fractii.out");

int have_common_div(int x, int y) {
    for (int i = 2; i <= min(x, y); ++i) {
        if (x % i == 0 && y % i == 0) {
            return 1;
        }
    }
    return 0;
}


long count_fractions(int n) {
    int count = 2*n - 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = 2; j <= n; ++j) {
            if (!have_common_div(i, j)) {
                count++;
            }
        }
    }
    return count;
}

int main() {
    int n;
    f >> n;
    g << count_fractions(n);
    return 0;
}


// #include <bits/stdc++.h>

// using namespace std;

// ifstream f("fractii.in");
// ofstream g("fractii.out");

// int smallest_prime_div(int x) {
//     if (x % 2 == 0) {
//         return 2;
//     }
//     int i = 3;
//     while (x % i) {
//         i += 2;
//     }
//     return i;
// }

// /*
// 1->10 1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10
// 2->5  2/1 2/3 2/5 2/7 2/9
// 3->7  3/1 3/2 3/4 3/5 3/7 3/9 3/10
// 5->8  5/1 5/2 5/3 5/4 5/6 5/7 5/8 5/9
// 6->5  6/1 6/5 6/7 (10 - 5 de la 2 si -3 de la 3 + 1 pt ca un 2 si un 3 se suprapun (6/6))
// 7->9 7/1 7/2 7/3 7/4 7/5 7/6 7/8 7/9 7/10


// */

// long count_fractions(int n) {
//     int count = n;
//     for (int i = 2; i <= n; ++i) {
//         cout << smallest_prime_div(i) << '\n';
//         count += (n - (n / smallest_prime_div(i)));
//     }
//     return count;
// }

// int main() {
//     int n;
//     f >> n;
//     g << count_fractions(n);
//     return 0;
// }