Cod sursa(job #1695673)

Utilizator werz66Nagy Peter werz66 Data 27 aprilie 2016 17:12:46
Problema Pascal Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.71 kb
program pascalhsz;
uses crt;
var f,g:text;
    d:byte;
    n,m,db,i,eredmeny:longint;
    a:array[0..6000000] of longint;

begin
        a[0]:=0;
        assign(f,'pascal.in');reset(f);
        assign(g,'pascal.out');rewrite(g);
        read(f,n);read(f,d);


        if (d=2) or (d=3) or (d=5) then begin
        for i:=1 to n do begin
                m:=i;
                while (m mod d)=0 do begin
                        m:=m div d;
                        inc(db);end;
                if i<=(n div 2) then
                        a[i]:=db
                        else a[i]:=a[n-i]+db;
                        end;end
        else if (d=4) then begin
                for i:=1 to n do begin
                m:=i;
                while (m mod 2)=0 do begin
                        m:=m div 2;
                        inc(db);end;
                if i<=(n div 2) then
                        a[i]:=db
                        else a[i]:=a[n-i]+db;
                        end;end
        else if (d=6) then begin
                for i:=1 to n do begin
                m:=i;
                while (m mod 2)=0 do begin
                        m:=m div 2;
                        inc(db);end;
                while (m mod 3)=0 do begin
                        m:=m div 3;
                        inc(db);end;
                if i<=(n div 2) then
                        a[i]:=db
                        else a[i]:=a[n-i]+db;
                        end;end;

        for i:=(n div 2)+1 to n do
                if db>a[i] then eredmeny:=eredmeny+2;
        if (n mod 2)=0 then
                if db>a[n div 2] then eredmeny:=eredmeny+1;

        write(g,eredmeny);
        close(f);close(g);
end.