zoukankan      html  css  js  c++  java
  • Light OJ 1058

    题意: 简单的就组合数 C(m,n);

    数据多,大, 要预处理;

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn = 1e6 + 2;
    const LL MOD = 1000003;
    
    LL Pow_Mod(LL a, LL n)
    {
        LL ret = 1;
        while(n)
        {
            if(n & 1) ret = ret * a % MOD;
            n >>=1;
            a = a * a % MOD;
        }
        return ret;
    }
    
    LL Num[maxn], Inv[maxn];
    LL Init()
    {
        Num[0] = 1;
        for(LL i = 1; i < maxn; ++i) Num[i] = Num[i-1] * i % MOD;
        //cout << Num[maxn-1] << endl;
        Inv[maxn-1] = Pow_Mod(Num[maxn-1], MOD-2);
        for(LL i = maxn-2; i >= 0; --i)
            Inv[i] = Inv[i+1] * (i+1) % MOD;
    }
    
    LL C(LL m, LL n)
    {
        LL ret = 1;
        if(n == 0 || n == m) return ret;
        else
        {
            LL s = m-n;
            //cout << s << endl;
            ret = Num[m] * Inv[s] % MOD;
            //cout << Num[m] << "   " << Inv[s] << endl;
            ret = ret * Inv[n] % MOD;
            //cout << Inv[n] << endl;
            return ret;
        }
    }
    
    int main()
    {
        Init();
        int t;
        LL m, n;
        scanf("%d",&t);
        for(int kase = 1; kase <= t; ++kase)
        {
            scanf("%lld %lld",&m,&n)    ;
            printf("Case %d: %lld
    ",kase, C(m,n));
        }
    }
    
  • 相关阅读:
    Jqeury ajax 调用C#的后台程序
    电商设计1
    智能分类
    网络爬虫框架Webmagic
    Spring Cloud 微服务架构解决方案
    网站流量日志数据分析系统1
    Shell 编程
    Zookeeper
    网站流量日志数据自定义采集
    分库分表的面试题5
  • 原文地址:https://www.cnblogs.com/aoxuets/p/5506860.html
Copyright © 2011-2022 走看看