Cod sursa(job #2544876)

Utilizator uneven-shiverAlecu Stefan-Iulian uneven-shiver Data 12 februarie 2020 17:03:30
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <vector>

constexpr size_t gcd(size_t a, size_t b) {
   if (a == 0) return b;
   if (b == 0) return a;

   if (a > 0) {
       if (a < b) return gcd(b - a, a);
       return gcd(a - b, b);
   }
   return b;
}

int main() {
    std::ifstream in("fractii.in");
    std::ofstream out("fractii.out");
    size_t N, answer = 0;
    in >> N;

    std::vector<size_t> fr(N , 0);
    for (size_t i = 0; i < N; i++) {
        for (size_t j = 0; j < N; j++) {
            if (gcd(i + 1, j + 1) == 1) fr[i]++;
        }
        answer += fr[i];
    }

    out << answer << std::endl;
    return 0;
}