Cod sursa(job #599147)

Utilizator andrianAndrian andrian Data 28 iunie 2011 03:43:47
Problema Fractii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
#define nmax 1000002

using namespace std;

unsigned long n, k=0;
unsigned long p[nmax];

void citire(){
    ifstream in("fractii.in");
    in >> n;
    in.close();
}


void afis(){
    for(unsigned long i=1;i<=n;++i) k+=p[i];
    k*=2;
    ++k;
    ofstream out("fractii.out");
    out << k;
    out.close();
}

void cerne(){
    for (unsigned long i = 1; i <= n; ++i)
        p[i] = i-1;
    for (unsigned long i = 2; i <= n; ++i)
        for (unsigned long j = 2*i; j <= n; j += i)
            p[j] -= p[i];
}

int main()
{
    citire();
    cerne();
    afis();
    return 0;
}