zoukankan      html  css  js  c++  java
  • 【BZOJ2982】combination Lucas定理

    【BZOJ2982】combination

    Description

    LMZn个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样。那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案mod 10007的值。(1<=m<=n<=200,000,000)

    Input

      第一行一个整数t,表示有t组数据。(t<=200)
      接下来t行每行两个整数n, m,如题意。

    Output

    T行,每行一个数,为C(n, m) mod 10007的答案。

    Sample Input

    4
    5 1
    5 2
    7 3
    4 2

    Sample Output

    5
    10
    35
    6

    题解百度:lucas定理

     

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define mod 10007
    using namespace std;
    int n,jc[10010],jcc[10010];
    int pm(int x,int y)
    {
    	int z=1;
    	while(y)
    	{
    		if(y&1)	z=z*x%mod;
    		x=x*x%mod,y>>=1;
    	}
    	return z;
    }
    int dfs(int x,int y)
    {
    	if(!y)	return 1;
    	if(x<y)	return 0;
    	if(x<mod&&y<mod)	return jc[x]*jcc[y]%mod*jcc[x-y]%mod;
    	return dfs(x/mod,y/mod)*dfs(x%mod,y%mod)%mod;
    }
    int main()
    {
    	scanf("%d",&n);
    	int i,a,b;
    	for(i=1,jc[0]=jcc[0]=1;i<=10007;i++)	jc[i]=jc[i-1]*i%mod,jcc[i]=pm(jc[i],mod-2);
    	for(i=1;i<=n;i++)
    	{
    		scanf("%d%d",&a,&b);
    		printf("%d
    ",dfs(a,b));
    	}
    	return 0;
    }
  • 相关阅读:
    连通域标记
    qt&gdal
    gdal vs2013编译
    java配置
    windows下面安装Python和pip
    mfc operator new”: 没有重载函数接受 3 个参数
    std::min&std::max与mfc冲突问题
    qt中vtk易出现错误
    cmake构建qt工程
    Webstorm补丁
  • 原文地址:https://www.cnblogs.com/CQzhangyu/p/6801578.html
Copyright © 2011-2022 走看看