描述 Description
n 的阶乘定义为 n!=123……n 如 3!=6。n! 通常最后会有很多 0,如 5!=120 最后有一个 0,现在统计 n! 去除末尾的 0 后,最后 k 位是多少?
输入格式 InputFormat
第一行包括两个数 n,k。
输出格式 OutputFormat
如果 n! 不止 k 位,则输出最后 k 位,如果不足 k 位,则高位补零,补足 k 位后输出。
样例输入 SampleInput
10 3
样例输出 SampleOutput
288
注释 Hint
100% 满足 1<=n<=1400000 1<=k<=10。
代码 Code
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>
using namespace std;
unsigned long long a;
stringstream stream;
string s;
int i,j,t,n,m,l,r,k,z,y,x;
int main()
{
scanf("%d%d",&n,&k);
a=1;
for (i=2;i<=n;i++)
{
a*=i;
while (a%10==0) a=a/10;
a%=1000000000000;
}
stream<<a;
stream>>s;
if (s.length()<k)
{
printf("0");
}
for (i=s.length()-k;i<s.length();i++) printf("%c",s[i]);
return 0;
}