The number of k digits of the factorial of the brush over a question

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.