Cod sursa(job #589821)

Utilizator vendettaSalajan Razvan vendetta Data 13 mai 2011 21:32:30
Problema Suma divizorilor Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.85 kb
const f='sumdiv.in';g='sumdiv.out';
    MAX = 100005 ;
    MDD = 9901 ;
var
    P : array [ 0 .. MAX ] of longint ;
    a,b, T,i1, j1 : longint ;
    V : array [ 0.. 1 shl 17 ] of byte ;
    sum, suma, N : int64 ;

procedure prec ;
    var
        i, j : longint ;

    begin
        inc ( P[0] ) ; P[ P[0] ] := 2 ;
        i := 1 ;
        while ( i * i shl 1 ) + ( i shl 1 ) <= MAX do
            begin
            if ( V[i shr 3] and ( 1 shl ( i and 7 ) ) ) = 0 then
                begin
                j := ( i * i shl 1 ) + ( i shl 1 ) ;
                while ( j shl 1 ) + 1 <= MAX do
                    begin
                    V[j shr 3] := V[j shr 3] or ( 1 shl ( j and 7 ) ) ;
                    inc ( j, ( i shl 1 ) + 1 ) ;
                    end ;
                end ;
            inc ( i ) ;
            end ;

        i := 1 ;
        while ( i shl 1 ) + 1 <= MAX do
            begin
            if ( V[i shr 3] and ( 1 shl ( i and 7 ) ) ) = 0 then
                begin
                inc ( P[0] ) ;
                P[ P[0] ] := ( i shl 1 ) + 1 ;
                end ;
            inc ( i ) ;
            end ;
    end ;

function pow ( N : longint ; P : longint ) : longint ;
    var
        i, sol : longint ;

    begin
        sol := 1 ; N := N mod MDD ; i := 0 ;
        while ( 1 shl i ) <= P do
            begin
            if ( ( 1 shl i ) and P ) > 0 then
                begin
                sol := sol * N ;
                sol := sol mod MDD ;
                end ;
            N := N * N ; N := N mod MDD ;
            inc ( i ) ;
            end ;
        pow := sol ;
    end ;


procedure ssnd(N : longint ) ;
    var
        i, nr, pp : longint ;
    begin
        //readln ( N ) ;
        nr := 1 ; sum := 1 ; i := 1 ;
        while ( int64 ( P[i] ) * int64 ( P[i] ) <= N ) and ( i <= P[0] ) do
            begin
            if ( N mod P[i] = 0 ) then
                begin
                pp := 0 ;
                while ( N mod P[i] ) = 0 do
                    begin
                    inc ( pp ) ;
                    N := N div P[i] ;
                    end ;
                //nr := nr * ( pp + 1 ) ;
                sum := sum * ( pow ( P[i], pp + 1 ) - 1 ); sum := sum mod MDD ;
                sum := sum * ( pow ( P[i] - 1, MDD - 2 ) ); sum := sum mod MDD ;
                end ;
            inc ( i ) ;
            end ;

        if ( N > 1 ) then
            begin
            //nr := nr shl 1 ;
            sum := sum * ( ( N + 1 ) mod MDD ); sum := sum mod MDD ;
            end ;
        //writeln ( nr, ' ', sum ) ;
    end ;


begin
    assign ( input, f) ; reset ( input ) ;
    assign ( output, g ) ; rewrite ( output ) ;

    prec ; //readln ( T ) ;
    readln( a,b );
    ssnd(pow(a,b));
    write(sum);
close ( input ) ; close ( output ) ;
end .