记录最后5位非0的数,然后就继续乘下去。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
freopen("fact4.in","r",stdin);
freopen("fact4.out","w",stdout);
int n,k=1,temp=10;
cin>>n;
for(int i=1;i<=n;i++)
{
k*=i;
while(!(k%10))
{
k/=10;
//temp*=10;
}
k%=100000;
}
cout<<k%10<<endl;
return 0;
}