UVA10212 【The Last Non-zero Digit.】

暴力可做!!!(十秒还不打暴力!!!)
暴力算阶乘
边算边取余
上代码

#include<iostream>
#define int long long        //开long long
using namespace std;
const int mod=1e9;
signed main()
{
    int n,m;
    while(scanf("%lld%lld",&n,&m)==2)   //多组数据
    {
        int ans=1;
        while(m--)
        {
            ans*=n--;
            while(ans%10==0)
                ans/=10;    //统计末尾0的个数
            ans%=mod;
        }
        printf("%lld\n",ans%10);
    }
    return 0;
}

 

猜你喜欢

转载自www.cnblogs.com/ivanovcraft/p/9021656.html