好吧,这个题我开始取最后一位的这样只过了4组吧,后来一怒之下取了4位就行了
//取最后四位分别进行运算,最后得到结果。好吧,三位也是可以的
#include <stdio.h>
#include <stdlib.h>
int deal(int n)
{
int ars;
while(n%1000==0)
{
n=n/10;
}
ars=n%1000;
return ars;
}
int main()
{
FILE *fin=fopen("fact4.in","r");
FILE *fout=fopen("fact4.out","w");
int n,ans=1,t,i;
fscanf(fin,"%d",&n);
for(i=1;i<=n;i++)
{
t=deal(i*ans);
ans=t;
while(ans%10==0) ans/=10;
}
fprintf(fout,"%d\n",ans%10);
return 0;
}