Cod sursa(job #2881251)

Utilizator RaduAntoneoAntonio Alexandru Radu RaduAntoneo Data 30 martie 2022 13:09:20
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>
using namespace std;

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

int cmmdc(int a, int b) {
    int aux;
    while(b) {
        aux = a % b;
        a = b;
        b = aux;
    }
    return a;
}

int main() {
    int n;
    f >> n;
    long long s = n;
    for(int i = 2; i <= n; i++) {
        int nr = 0;
        for(int j = 1; j <= n; j++) {
            if(cmmdc(i, j) > 1) nr++;
        }
        s += (n - nr);
    }
    g << s;
    return 0;
}