Cod sursa(job #529061)

Utilizator crisjonycristi crisjony Data 4 februarie 2011 09:33:32
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.31 kb
var
        n,p,k,i,x:longint;
procedure citire;
var f:text;
begin
        assign(f,'factorial.in');
        reset(f);
        read(f,p);
        close(f);
end;

procedure determinare;
var m,t:longint;
begin
        n:=1;
        repeat
                if n=1 then
                        x:=0
                else
                begin
                        k:=0;
                        m:=0;
                        t:=0;
                        for i:=1 to n do
                        begin
                                if i mod 10=2 then
                                        inc(k);
                                if i mod 10=5 then
                                        inc(m);
                                if i mod 10=0 then
                                        inc(t);
                        end;
                        if (m>=k)and(m<>0)and(k<>0) then
                                x:=k+t;
                        if (k>=m)and(m<>0)and(k<>0) then
                                x:=m+t;
                end;
                inc(n);
        until x=p;
end;
procedure afisare;
var g:text;
begin
        assign(g,'factorial.out');
        rewrite(g);
        write(g,n-1);
        close(g);
end;

begin
        citire;
        determinare;
        afisare;
end.