Cod sursa(job #44231)

Utilizator Bluedrop_demonPandia Gheorghe Bluedrop_demon Data 30 martie 2007 23:49:14
Problema Fractii Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.35 kb
{
    Problema fractii
    Versiunea n.00
}

Program fractii;

Type vector = array[1..1000000] of Longint;

Var nr, boom : int64;
    c, c2, t : vector;
    n, i, j, aux, k : longint;

Function totient( m : longint ) : Longint;
Var i, rez : Longint;
Begin
    rez := m;
    i := 1;
    While ( i<=k ) and (c2[i] <= m) do
        Begin
            if m mod c2[i] = 0 then
                Begin
                    rez := rez div c2[i];
                    rez := rez*(c2[i]-1);
                End;
            i := i+1;
        End;
    totient := rez;
End;

Begin
    Assign( input, 'fractii.in' );
    Reset( input );
        Readln( n );
    Close( input );


    k := 0;
    For i := 2 to n do
        Begin
        If c[i] = 0 then
            Begin
                k := k+1;
                c2[k] := i;
                aux := i;
                j := aux;
                While j <= n do
                    Begin
                        j := j+aux;
                        c[j] := 1;
                    End;
            End;
            t[i]  := totient( i );
        End;

    nr := 1;
    For i := 2 to n do
        Begin
            boom := t[i] shl 1;
            nr := nr + boom;
        End;


    Assign( output, 'fractii.out' );
    Rewrite( output );
        Writeln( nr );
    Close( output );
End.