Cod sursa(job #1935313)

Utilizator TheodorVladParaschiv Theodor Vlad TheodorVlad Data 22 martie 2017 10:45:49
Problema Factorial Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.65 kb
Program nume;
var f,g:text;
p,s,y,suma,z:longint;
c:integer;
function putere (t:integer):longint;
var m:longint;
begin
m:=1;
while (t>0) do
begin
m:=m*5;
t:=t-1;
end;
putere:=m;
end;
begin
assign (f,'fact.in');
reset (f);
assign (g,'fact.out');
rewrite (g);
read (f,p);
c:=0;
suma:=putere(c);
while (suma<p) do
begin
suma:=suma*5;
c:=c+1;
end;

if (p=0) then
write (g,1)
else
begin
y:=trunc((p+c)*4/(5-1/putere(c)));
if (y<100) then
y:=0
else
y:=y-200;
repeat
s:=y;
for z:=1 to c do
s:=s+trunc(y/putere(z));
y:=y+1;
until (s>=p);
write (g,5*(y-1));
end;
{writeln (g,c);
write (g,y);   }
close (f);
close (g);
end.