算法:模拟
分析:其实就是一道模拟题,直接用高精度求阶乘把末尾的0去掉就行了,因为我们要求的是第一个末尾不是0的个数,所以末尾的0有多少个与所求问题无关,直接忽略掉。
program fact4;
var
n:longint;
ans:ansistring;
function gjc(x,y:ansistring):ansistring;
var
i,j,jinwei,lena,lenb,rlena,rlenb,len,t:longint;
ts:ansistring;
a,b,c:array [0..1000] of longint;
begin
gjc:='';
fillchar(c,sizeof(c),0);
lena:=length(x) div 4;
rlena:=length(x)-lena*4;
lenb:=length(y) div 4;
rlenb:=length(y)-lenb*4;
for i:=1 to lena do val(copy(x,length(x)-4*i+1,4),a[i]);
if copy(x,1,rlena)<>'' then
begin
inc(lena);
val(copy(x,1,rlena),t);
a[lena]:=t;
end;
for i:=1 to lenb do val(copy(y,length(y)-4*i+1,4),b[i]);
if copy(y,1,rlenb)<>'' then
begin
inc(lenb);
val(copy(y,1,rlenb),t);
b[lenb]:=t;
end;
for i:=1 to lena do
begin
jinwei:=0;
for j:=1 to lenb do
begin
jinwei:=a[i]*b[j]+jinwei div 10000+c[i+j-1];
c[i+j-1]:=jinwei mod 10000;
end;
c[i+j]:=jinwei div 10000;
end;
len:=lena+lenb;
while (c[len]=0) and (len>1) do dec(len);
for i:=len downto 1 do
begin
str(c[i],ts);
gjc:=gjc+ts;
end;
end;
procedure main;
var
i,j,st:longint;
t:ansistring;
begin
ans:='1';
for i:=2 to n do
begin
str(i,t);
ans:=gjc(ans,t);
for j:=length(ans) downto 1 do if ans[j]<>'0' then break;
if (j<>1) and (ans[j]<>'0') then delete(ans,j+1,length(ans)-j);
end;
end;
begin
assign(input,'fact4.in'); reset(input);
assign(output,'fact4.out'); rewrite(output);
readln(n);
main;
writeln(ans[length(ans)]);
close(input); close(output);
end.