The factorial of n is defined as n!=1*2*3*......*n, such as 3!=6, a special 0!=1. N! usually end up with a lot of 0, such as 5!=120, finally there is a 0, now statistics n! Remove the end of 0 (note is the tail of all 0, also means to see from right to left the first non-0 digits to the right of all 0 are removed), the last K-bit is how much.
Input:
Only one row consists of two number n,k, and two numbers are separated by a space.
Output:
If the n! remove the tail of the 0 after the K-bit, then the output of the last K-bit, if the K-bit is not enough, then the high 0, to complement the K-bit output.
Input Example:
9 |
Output Example:
04
Sample Description: 7! Is 5040, the end of 0 is removed to 504, the last two bits are 04, so the output is 04.
Data range: 100% meet 1<=n<=1400000,1<=k<=10
Water problem, not explained
1#include <iostream>2 #definell Long Long3 using namespacestd;4ll n,k,ans=1, mod=1, Len;5 intIntlen (ll x)6 {7 while(x) {x/=Ten; len++;}8 }9 intMain ()Ten { OneCin>>n>>K; A for(intI=1; i<=k;i++) mod*=Ten; - if(k==1) mod=Ten; - for(intI=2; i<=n;i++) the { -ans*=i; - while(ans%Ten==0) ans/=Ten; -ans%=mod*Ten; + } -ans%=MoD; + Intlen (ans); A for(intI=1; i<=k-len;i++) cout<<'0'; atcout<<ans; - //System ("Pause>nul"); - return 0; -}
The number of k digits of the factorial of the brush over a question