分析:这个题目最主要的问题就是阶乘之后的数字太大,没有哪个类型能放下,但是题目只要求输出最后的非零数字,这样就不必保留全部位的数字了,只需保留第一位非零数字及其前面的3位就可以了。
代码:
/*
ID: supersnow0622
PROG: test
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
long long arr[4221];
int main() {
ofstream fout ("test.out");
ifstream fin ("test.in");
int N;
cin>>N;
arr[0]=1;
int a=1;
while(a<=N)
{
arr[a]=arr[a-1]*a;
while(arr[a]/10!=0&&arr[a]%10==0)
{
arr[a]/=10;
}
arr[a]%=1000;
a++;
}
while(arr[N]%10==0)
{
arr[N]/=10;
}
cout<<arr[N]%10;
return 0;
}