Cod sursa(job #107442)

Utilizator mirhciulicaMircea Stefan Ghideu mirhciulica Data 19 noiembrie 2007 20:47:15
Problema Factorial Scor 15
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.49 kb
var p,n,i,nr,z:longint;
    x:array[1..10000]of longint;
    y:array[1..10000]of byte;
    f,g:text;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);x[1]:=1;
for i:=2 to 10000 do
begin
x[i]:=1;x[i]:=x[i-1]*x[i];
z:=x[i];
while z mod 10=0 do
begin z:=z div 10;inc(y[i]);end;end;
if p=0 then
writeln(g,1)
else if p=1 then writeln(g,-1) else begin
i:=1;
while p<=y[i] do
inc(i);
if p=y[i] then
writeln(g,x[i])
else writeln(g,-1);
end;
close(g);
end.