zoukankan      html  css  js  c++  java
  • LightOJ

    nCr * pq

    求该表达式末尾0的个数。

    显然至于2 5 的因子个数有关。

    考虑预处理出每个数的2,5的因子个数,并统计前缀和(题个的组合数其实是阶乘)

    int _2[maxn], _5[maxn];
    ll _s2[maxn], _s5[maxn];
    
    int _count(int x, int y) {
        int res = 0;
        while (x % y == 0) x /= y, res++;
        return res;
    }
    
    void init() {
        for (int i = 2; i < maxn; i++) {
            _2[i] = _count(i, 2);
            _5[i] = _count(i, 5);
            _s2[i] = _s2[i - 1] + _2[i];
            _s5[i] = _s5[i - 1] + _5[i];
        }
    }
    
    int main() {
        init();
        int T = readint();
        int n, r, p, q;
        int kase = 1;
        while (T--) {
            n = readint(), r = readint(), p = readint(), q = readint();
            int c1 = _s2[n], c2 = _s5[n];
            c1 -= _s2[r] + _s2[n - r];
            c2 -= _s5[r] + _s5[n - r];
            int c3 = _2[p] * q;
            int c4 = _5[p] * q;
            printf("Case %d: %d
    ", kase++, min((c1 + c3), (c2 + c4)));
        }
    }
  • 相关阅读:
    S03E01 蓝牙操作
    GET与POST方法
    Http请求头与响应头
    HttpClient初步
    Http
    深度为H的满k叉树
    html5-css选择器
    html5-css的使用强制优先级
    html5-样式表的使用-初步
    html5-css的引入
  • 原文地址:https://www.cnblogs.com/hznumqf/p/13508810.html
Copyright © 2011-2022 走看看