• Trailing Zeroes (II) LightOJ


    求C(n,r)*p^q的后缀零

    考虑一下 是不是就是求 10^k*m  的k的最大值

    而10又是由2 和 5 组成  所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛。。
    预处理每个 1 - 1e6 的每个数字的对2分解,对5分解的次数  然后还要保存下前缀和  作为 n的阶乘中分别包含的次数

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 1e6 + 10, INF = 0x7fffffff;
    int sum1[maxn], sum2[maxn], a[maxn], b[maxn];
    
    
    int count_(int a, int b)
    {
        int cnt = 0;
        while(a % b == 0)
        {
            cnt++;
            a/=b;
        }
        return cnt;
    }
    
    int main()
    {
        for(int i=2; i<maxn; i++)
        {
            a[i] = count_(i, 2);
            b[i] = count_(i, 5);
            sum1[i] += sum1[i-1] + a[i];
            sum2[i] += sum2[i-1] + b[i];
        }
        int n, r, p, q, T, kase = 0;
        cin>> T;
        while(T--)
        {
            cin>> n >> r >> p >> q;
            int c = sum1[n] - sum1[r] - sum1[n-r];
            int d = sum2[n] - sum2[r] - sum2[n-r];
            int e = a[p] * q;
            int f = b[p] * q;
            cout<< "Case "<< ++kase <<": " <<min(c+e, d+f) <<endl;
        }
    
    
        return 0;
    }
    View Code


      

    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    Final Zadanie 题解
    CF1096E The Top Scorer 题解
    [SDOI2008]Sue的小球 题解
    柱爷与远古法阵 题解
    [ZOJ3329] One Person Game 题解
    扑克牌 题解
    CF494C Helping People 题解
    CF1025D Recovering BST 题解
    linux基础学习-Raid 0 1 5 10的原理、特点、性能区别
    linux基础学习-CentOS7.5用户管理
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9349455.html
Copyright © 2020-2023  润新知