Cod sursa(job #2628955)

Utilizator Rares_RacsanRacsan Rares Vasile Rares_Racsan Data 18 iunie 2020 12:51:57
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("fractii.in");
ofstream fout("fractii.out");
int n, i = 0, j = 0;
int v[1000001];
long long total = 0;

int main()
{
    fin >> n;
    for(i = 1; i <= n; i++)
    {
        v[i] = i;
    }
    for(i = 2; i <= n; i++)
    {
        if(v[i] == i)
        {
            for(j = i; j <= n; j=j+i)
            {
                v[j] /= i;
                v[j] *= (i-1);
            }
        }
    }
    total = 1;
    for(i = 2; i <= n; i++)
    {
        total = total + 2 * v[i];
    }
    fout << total;
    return 0;
}