Cod sursa(job #669070)

Utilizator psycho21rAbabab psycho21r Data 26 ianuarie 2012 00:56:36
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>

using namespace std;

bool a[400];

int main()
{
    int n;
    float phi[400];
    ifstream in("fractii.in");
    in >> n;
    in.close();
    a[1] = 1;
    for (int i = 1; i <= n; ++i)
        phi[i] = i;
    for (float i = 2; i <= n; ++i)
    {
        if (!a[int(i)])
        {
            phi[int(i)]=i-1;
            for (float j = 2*i; j <= n; j+=i)
            {
                a[int(j)] = 1;
                phi[int(j)]*=((i-1)/i);
            }
        }
    }

    int total=0;

    for (int i = 2; i<=n;++i)
        total+=int(phi[i]);
    ofstream out("fractii.out");
    out << 2*total + 1;
    out.close();
    return 0;
}