Cod sursa(job #2788123)

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

int e[1000005] = {};

int main() {
    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);
}