Cod sursa(job #54384)

Utilizator DastasIonescu Vlad Dastas Data 24 aprilie 2007 19:53:21
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;

ifstream in("fractii.in");
ofstream out("fractii.out");

int n;
long long pr[78500];

void prime()
{
    char a[1000000] = {0};

    int cnt = 1;
    int p = sqrt(n)+1;
    pr[0] = 2;
    for ( int i = 3; i <= n; i += 2 )
    {
        if ( a[i] == 0 )
        {
            pr[cnt++] = i;
            if ( i <= p )
            {
                for ( int j = (i<<1); j <= n; j += i )
                    a[j] = 1;
            }
        }
    }
}

long long tot(int x)
{
    double res = x;

    for ( int i = 0; i <= x; ++i )
        if ( pr[i] != 0 )
        {
            if ( x % pr[i] == 0 )
                res = res * (1.0-(1.0/pr[i]));
        }
        else
            break;

    return ceil(res);
}

int main()
{
    in >> n;
    prime();
//
    long long sol = 0;
//    int i = 0;
//    char viz[1000000] = {0};
//
//    while ( pr[i] )
//    {
//        for ( int t = pr[i]; t <= n; t += pr[i] )
//        {
//            //cout << t << " " << tot(t) << endl;
//            if ( !viz[t] )
//                sol += tot(t);
//            viz[t] = 1;
//        }
//        ++i;
//    }
//
//    sol = sol*2 + 1;

    out << sol << endl;



	return 0;
}