Cod sursa(job #2788124)

Utilizator matthriscuMatt . matthriscu Data 25 octombrie 2021 00:10:17
Problema Fractii Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>
#include <stdbool.h>

int e[1000005] = {};

int main() {
    freopen("fractii.in", "r", stdin);
    freopen("fractii.out", "w", stdout);
    int n, i, j;
    unsigned long long ans = 1;
    bool p[1000005] = {};
    scanf("%d", &n);
    for(i = 1; i <= n; ++i)
        e[i] = i;
    for(i = 2; i <= n; ++i)
        if(p[i] == 0) {
            for(j = i; j <= n; j += i) {
                p[j] = 1;
                e[j] = e[j] / i * (i-1);
            }
        }
    for(i = 2; i <= n; ++i)
        ans += 2*e[i];
    
    printf("%lld\n", ans);
}