水题吧?有一个陷阱,不能仅仅保留结果的最后一位,例如14!的最后一位是2,计算2*15,最后一位非零数字是3,其实这是错的,这里因为n<=4220<10000,所以应该保留4位。
/*
ID:jzzlee1
PROB:fact4
LANG:C++
*/
//#include<iostream>
#include<fstream>
using namespace std;
ifstream cin("fact4.in");
ofstream cout("fact4.out");
int cal(int x)
{
while(x%10==0)
x/=10;
return x>10000?x%10000:x;
}
int main()
{
int n;
cin>>n;
int i,ans=1;
for(i=2;i<=n;i++)
{
ans*=i;
ans=cal(ans);
}
ans%=10;
cout<<ans<<endl;
return 0;
}