886. 求组合数 II(模板)

数据范围较大, 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(模板)的更多相关文章
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- 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 ...
- 牛客小白月赛14 -B (逆元求组合数)
题目链接:https://ac.nowcoder.com/acm/contest/879/B 题意:题目意思就是求ΣC(n,i)pi(MOD+1-p)n-i (k<=i<=n),这里n,i ...
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- 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)( ...
- pku1365 Prime Land (数论,合数分解模板)
题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: ; ans != ; ++i) { ) { num ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- 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 ...
随机推荐
- GTMD并查集!
徐州的A我因为并查集写错T了整场.. int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } GTMD!
- BZOJ 1025 [SCOI2009]游戏 (DP+分解质因子)
题意: 若$a_1+a_2+\cdots+a_h=n$(任意h<=n),求$lcm(a_i)$的种类数 思路: 设$lcm(a_i)=x$, 由唯一分解定理,$x=p_1^{m_1}+p_2^{ ...
- SpringBoot学习笔记 文件访问映射
通过SpringBoot可以把磁盘内所有的文件都访问到 有一张图片存放在 E://images/acti/123.jpg import org.springframework.context.anno ...
- SNMP协议交互学习-获取udp的udpindatagrams
MIB的组织结构,如下左图,对于udp来说1.3.6.1.2.1.7,组织如下右图,包括4个标量和1个表格 udp节点在LwIP中的定义如下: ] = { , , , , }; ] = { (stru ...
- [MSSQL]xp_cmdshell 查看磁盘空间
EXEC xp_cmdshell 'wmic logicaldisk get freespace,caption | findstr C'; <class 'pyodbc.Row'> (' ...
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
- 杭电-------2046骨牌铺方格(C语言写)
#include<stdio.h> ] = { }; long long recrusion(int n) { || a[n]>) { return a[n]; } ) + recr ...
- vue 鼠标移入移出 列表蒙层展示
<template> <section class="base"> <ul> <li v-for="(item, index) ...
- redis教程-基础数据结构
需要整套redis缓存高可用集群教学视频的加qq:1324981084,本套视频从安装到集群的搭建和源码的解析,从零基础讲解. 一.Redis 有 5 种基础数据结构,分别为:string (字符串) ...
- 秘钥分割-Shamir秘钥分割门限方案
精选: 1.问题的提出 2.需求的抽象: 有一个秘钥S,转换成另一种数据数据形式,分配给12个人(s1,s2,.......,s12),使得任意3个人的数据拼凑在一起就可以反向计算出秘钥S. 3.解决 ...