POJ 1604
题意
求n!最后一位非零数字
思路
网上学习别人的代码后,截取n!的后五位避免超出int的范围
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int s[10005];
int n;
void multiply(){
int i,j;
memset(s,0,sizeof(s));
s[1] = 1;
j = 1;
for(i = 2;i <= 10000;i++){
j *= i;
while(j %10 == 0)
j /= 10;
j %= 10000;
s[i] = j%10;
}
}
int main()
{
multiply();
while(cin>>n){
printf("%5d",n);
cout<<" -> "<<s[n]<<endl;
}
return 0;
}