作业帮 > 综合 > 作业

n的阶乘问题1、n的阶乘定义为n!=1*2*3*……*n 如3!=6通常最后会有很多0,如5!=120 最后有一个0,现

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 01:58:35
n的阶乘问题
1、n的阶乘定义为n!=1*2*3*……*n 如3!=6
通常最后会有很多0,如5!=120 最后有一个0,现在统计n!去除末尾的0后,最后k位是多少?
如果n!不止k位,则输出最后k位,如果不足k位,则将剩下的全部输出
输入n,k
输入:7,2
输出:04
program chy1;
const maxn=1000;
var a:array[0..maxn]of longint;
i,j,n,e,m,t,s,q:longint;
begin
readln(n);
a[0]:=1;
for i:=1 to n do begin
e:=0;
for j:=0 to a[maxn] do begin
e:=e+a[j]*i;
a[j]:=e mod 10;
e:=e div 10;
end;
while e>0 do
begin a[maxn]:=a[maxn]+1; a[a[maxn]]:=e mod 10; e:=e div 10; end;
end;
for i:=a[maxn] downto 0 do write(a[i]);
writeln;
s:=a[maxn];
t:=0;
repeat
if a[t]=0 then s:=s-1;
t:=t+1;
until a[t]0;
for i:=s+t downto t do write(a[i]);
read(q);
for i:=q downto t do
write(a[i]);
readln
end.