2982: combination

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 611  Solved: 368
[Submit][Status][Discuss]

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
 
思路:
卢卡斯定理裸题
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10008
#define ll long long
#define mod 10007
using namespace std;
ll t,n,m,ans,f[N];
ll read()
{
    ll x=,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
ll qpow(ll n,ll k)
{
    ll res=;
    while(k)
    {
        ) res=res*n%mod;
        n=n*n%mod; k>>=;
    }return res;
}
ll c(ll n,ll m)
{
    ;
    )%mod;
}
ll lus(ll n,ll m)
{
    ) ;
    return c(n%mod,m%mod)*lus(n/mod,m/mod)%mod;
}
int main()
{
    t=read();f[]=;
    ;i<=mod;i++)
     f[i]=f[i-]*i%mod;
    while(t--)
    {
        n=read(),m=read();
        ans=lus(n,m);
        printf("%lld\n",ans);
    }
    ;
}

bzoj——2982: combination的更多相关文章

  1. ZOJ 3557 & BZOJ 2982 combination[Lucas定理]

    How Many Sets II Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...

  2. BZOJ 2982: combination( lucas )

    lucas裸题. C(m,n) = C(m/p,n/p)*C(m%p,n%p). ----------------------------------------------------------- ...

  3. bzoj 2982 combination——lucas模板

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 明明是lucas定理裸题…… 非常需要注意C( )里  if ( n<m ) r ...

  4. BZOJ 2982 combination

    lucas定理裸题. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  5. BZOJ 2982 combination Lucas定理

    题目大意:发上来就过不了审核了--总之大意就是求C(n,m) mod 10007 m,n∈[1,2*10^8] 卢卡斯定理:C(n,m)=C(n%p,m%p)*C(n/p,m/p) mod p 要求p ...

  6. BZOJ 2982 combination 脑子+组合数学

    可以发现,整个数列构成一个树形结构,并且是个完全二叉堆(小根堆). 并且这个堆的形态在给定$n$后是固定的,第1个位置上显然只能放1. 对子树的根来说,他自己是所分得的数集中最小的那个,所以从剩下$s ...

  7. BZOJ 2982: combination Lucas模板题

    Code: #include<bits/stdc++.h> #define ll long long #define maxn 1000003 using namespace std; c ...

  8. 【BZOJ 2982】 2982: combination (卢卡斯定理)

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 510  Solved: 316 Description LMZ有n个 ...

  9. 【BZOJ】2982: combination(lucas定理+乘法逆元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2982 少加了特判n<m return 0就wa了QAQ lucas定理:C(n, m)%p=( ...

随机推荐

  1. RecycleView的简单应用

    recycleView在界面展示上类似于ListView,但不同于ListView的是它展示的每一个item类型可以不一样:    RecycleAdapter类: public class Recy ...

  2. Scala-基础-运算符

    import junit.framework.TestCase /** * 运算符 */ class Demo3 extends TestCase { def test_+ { var x = 10; ...

  3. ReLU激活函数:简单之美

    出自 http://blog.csdn.net/cherrylvlei/article/details/53149381 导语 在深度神经网络中,通常使用一种叫修正线性单元(Rectified lin ...

  4. ElasticSearch 安装使用

    安装: 1.下载ElasticSearch.解压到相关文件夹 2.运行elasticsearch.bat,启动程序 3.在浏览器输入:http://localhost:9200/,显示相关Es内容即安 ...

  5. js获取地址栏参数2种最简单方法

    NO1:(本人最喜欢) //普通参数 function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name ...

  6. 如何创建C# Closure?

    JavaScript中一个重要的概念就是闭包,闭包在JavaScript中有大量的应用,但是你知道么?C#也可以创建Closure.下面就介绍一下如何在C#中创建神奇的闭包. 在这之前,我们必须先知道 ...

  7. PHP7 上传文件报错 Internal Server Error 解决方法

    打开Apache配置httpd.conf.在最后添加FcgidMaxRequestLen指令一个足够大的值(以字节为单位),例如 FcgidMaxRequestLen 100000000 最后重新启动 ...

  8. 平凡的世界小说txt下载完整版

    <平凡的世界>正白纸黑字的告诉我们这样的人生真谛.它响亮的提出,人,无论在什么位置,无论多么贫寒,只要一颗火热的心在,只要能热爱生活,上帝对他就是平等的.只有作一名劳动者,不把不幸当作负担 ...

  9. Codeforces_768_B_(二分)

    B. Code For 1 time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  10. JavaScipt30(第五个案例)(主要知识点:flex布局)

    承接上文,这是第5个案例:这节没什么讲的,随便记录下吧,主要是用了flex布局与transform translateY,js部分和案例1类似. 附上项目链接: https://github.com/ ...