zoukankan      html  css  js  c++  java
  • 随机数

    无穷的公式

    a/b%mod=a*(b^(mod-2))%mod  表示a乘b的(mod-2)次方      mod是素数

    即s[n]/(s[n-m]*s[m])%mod==s[n]*pow(s[n-m],mod-2)*pow(s[m],mod-2)%mod   因为幂比较大   所以要用大指数幂的公式

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <cmath>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    typedef long long LL;
    
    const int maxn=1000007;
    const int INF=0x3f3f3f3f;
    const int mod=1000003;
    
    LL s[maxn];
    
    LL fun(LL x, LL n)
    {
        LL res=1;
    
        while(n>0)
        {
            if(n & 1)
                res=(res*x)%mod;
            x=(x*x)%mod;
            n>>=1;
        }
        return res;
    }
    
    void work()
    {
        s[0]=1;
        for(int i=1;i<maxn;i++)
            s[i]=s[i-1]*i%mod;
    }
    
    int solve(int n,int m)
    {
        LL ans=1;
        ans=s[n]*fun(s[n-m],mod-2)%mod*fun(s[m],mod-2)%mod;
        return (int)ans;
    }
    
    int main()
    {
        int T,n,m,cas=1;
        work();
        scanf("%d",&T);
    
        while(T--)
        {
            scanf("%d%d", &n, &m);
            printf("Case %d: %d
    ", cas++, solve(n,m));
        }
    
        return 0;
    }
  • 相关阅读:
    大数据集群实验环境搭建
    ORACLE 自治事物
    UNDO内存结构剖析
    事物深度解析
    UNDO
    SCN
    检查点队列
    WPS Excel启用正则表达式
    Python遍历目录下xlsx文件
    Python 字符串指定位置替换字符
  • 原文地址:https://www.cnblogs.com/w-y-1/p/5760200.html
Copyright © 2011-2022 走看看