摆渡人小说创作灵感:tju1011的题目结果对,却不能ac,帮忙修改一下,感激不已

来源:百度文库 编辑:高校问答 时间:2024/04/28 03:46:19
题目:
Problem对于小于25000的自然数n,求阶乘n!,(n-1)!,(n-2)!...3!,2!,1!右边的非零数之和。

例如:

当n=5时,
5!=120,右边非零数为2;
4!=24,右边非零数为4;
3!=6,右边非零数为6;
2!=2,右边非零数为2;
1!=1,右边非零数为1。
其右边的非零数之和为15。

Input
本题有多组数据,每组数据包含一个正整数N(N不大于25000)占一行。

Output
对给定的每组输入数据,输出一个整数。每个结果占一行。不要输出额外的空行。

Sample Input
5
10
1

Sample Output
15
39
1

我的程序:
program dd;
var n,i,j,t:word;
begin
while not seekeof(input) do begin
readln(n);
j:=1;t:=0;
for i:=1 to n do begin
j:=j*i;
if j mod 10=0 then j:=j div 10 else j:=j mod 10;
t:=t+j;
end;
writeln(t);
end;
end.

把你所有的word变量换成longint试下先,有溢出的可能。我好久没做tju乐,不知现在能排名第几。

if j mod 10=0 then j:=j div 10 else j:=j mod 10;

最好改为
while (j mod 10=0) do j:=j div 10;
j:=j mod 10;