Cod sursa(job #2630880)

Utilizator Andrei_KAndrei K. Andrei_K Data 27 iunie 2020 17:53:52
Problema Fractii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

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

int a[1000001];

int main()
{
    int n, s = 0;
    f >> n;
    for (int i = 2; i <= n; i++)
    {
        s += (a[i] += i - 1);
        for (int j = 2 * i; j <= n; j += i)
            a[j] -= a[i];
    }
    g << 1 + 2 * s;
    return 0;
}
/*
[1, 2, 3, 4]
 1  1    -1
 1  1  2 -1
 1  1  2  2


[1, 2, 3, 4, 5, 6]
 1  1    -1    -1
 1  1  2 -1    -3
 1  1  2  2  4  2


[1, 2, 3, 4, 5, 6, 7, 8, 9]
 1  1    -1    -1    -1
 1  1  2 -1    -3    -4 -3
 1  1  2  2  4  2  6  4  5
*/