Cod sursa(job #5333)

Utilizator vanila0406Ionescu Victor vanila0406 Data 11 ianuarie 2007 22:32:57
Problema GFact Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.72 kb
program gfact;
var p,q:longint;
        f,g:text;
        divizor,putere:longint;



procedure iofile;
var d,e:longint;
begin
        assign(f,'gfact.in');
        reset(f);
        assign(g,'gfact.out');
        rewrite(g);
        readln(f,p,q);
        d:=2;
        while p<>1 do
                begin
                        e:=0;
                        while p mod d=0 do
                                begin
                                        p:=p div d;
                                        inc(e);
                                end;
                        inc(d);
                end;
        divizor:=d-1;
        putere:=e*q;
        close(f);
end;





procedure prel;
var i:longint;
        put,x,d:longint;
begin
        put:=0;
        i:=0;
        while put<putere do
                begin
                        if i+divizor>putere then
                                begin
                                        x:=putere-i;
                                        put:=put+x;
                                        i:=i+x;
                                end else
                        begin
                                put:=put+divizor;
                                i:=i+divizor;
                                x:=i;
                                while x mod divizor =0 do
                                        begin
                                                inc(put);
                                                x:=x div divizor;
                                        end;
                        end;
                end;

        writeln(g,i*divizor);
        close(g);
end;



begin
        iofile;
        prel;
end.