数据范围较大, a,b都是1e5

直接根据公式预处理

 

 1/i就是求i的逆元(逆元求法:mod为质数,逆元就是 i^(mod-2)%mod )

O(N*logN)

import java.util.Scanner;

public class Main{
static final int N=100005;
static final int mod=(int)1e9+7;
static long fact[]=new long[N];
static long infact[]=new long[N];
static long quick_pow(long a,long b){
long res=1;
while(b>0){
if((b&1)==1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
fact[0]=infact[0]=1;
for(int i=1;i<N;i++){
fact[i]=fact[i-1]*i%mod;
infact[i]=infact[i-1]*quick_pow(i,mod-2)%mod;
}
int t=scan.nextInt();
while(t-->0){
int a=scan.nextInt();
int b=scan.nextInt();
System.out.println(fact[a]*infact[a-b]%mod*infact[b]%mod);
}
}
}

886. 求组合数 II(模板)的更多相关文章

  1. lucas求组合数C(n,k)%p

    Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...

  2. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  3. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  4. 牛客小白月赛14 -B (逆元求组合数)

    题目链接:https://ac.nowcoder.com/acm/contest/879/B 题意:题目意思就是求ΣC(n,i)pi(MOD+1-p)n-i (k<=i<=n),这里n,i ...

  5. URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理

    URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...

  6. N!分解质因子p的个数_快速求组合数C(n,m)

    int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...

  7. pku1365 Prime Land (数论,合数分解模板)

    题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: ; ans != ; ++i) { ) { num ...

  8. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  9. hdu 2519 求组合数

    求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...

随机推荐

  1. mongo 集群(副本)搭建过程记录

    最近搭建mongo集群,回忆总结,作以记录.整个过程主要参考以下两篇文章,但是过程并不顺利,有些问题需要记录.https://www.cnblogs.com/dba-devops/p/7130710. ...

  2. GDB gdb 调试

    除了用grmon看汇编调试外,还可以用gdb. 编译的时候加-g gdb app即可进入gdb调试 设置断点:b main.c:10 然后运行程序:run 断点处可以查看变量:display a 其它 ...

  3. logstash 配置文件语法

    需要一个配置文件 管理输入.过滤器和输出相关的配置.配置文件内容格式如下: # 输入 input { ... } # 过滤器 filter { ... } # 输出 output { ... } 先来 ...

  4. linux 手工释放内存 高内存 内存回收 方法思路

    linux  跑的apache,apache工作模式有   Prefork.Worker和 Event  三种,分别是基于进程.线程.综合模式.        本文中使用的apache是 Event  ...

  5. 配置ASA防火墙 远程管理方式

          受不了,asa和思科路由器 系统命令不一致,这一篇专门来写asa.      先看下版本 asa825# show version      Cisco Adaptive Security ...

  6. Webpack中hash、chunkhash和contenthash三者的区别

    在webpack中有三种的方式生成哈希值,分别为hash.chunkhash和contenthash.这三种方式有着不同的用处,或者说在webpack的不同环境中,会使用不同的方式生成哈希值.那为什么 ...

  7. linux之ls目录处理命令

    目录处理命令:ls 解释 命令名称:ls 命令英文原意:list 命令所在路径:/bin/ls 执行权限:所有用户 功能描述:显示目录文件 语法 ls 选项[-ald] [文件或目录] -a 显示所有 ...

  8. mysql 查询语句的执行顺序(重重点)

    一 SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_table> <join_type> JOI ...

  9. vue中允许你继续使用swiper的组件 vue-awesome-swiper---切图网

    swiper是一个在切图中好用到不行的图片轮播插件,包括3d轮播.h5滑屏等复杂应用都不在话下,到了vue项目一切逻辑完全颠覆了,没有获取dom的概念,还好有 vue-awesome-swiper组件 ...

  10. 使用placeholder属性设置input文本框的提示信息

    input文本框中设置提示信息,可以使用placeholder属性 <!DOCTYPE html> <html> <head> <meta charset=& ...