一本通1656:Combination

1656:Combination

时间限制: 1000 ms         内存限制: 524288 KB
提交数: 89     通过数: 49

【题目描述】

原题来自:BZOJ 2982

LMZ 有 n


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

的值。

【输入】

第一行一个整数 t


,表示有 t

组数据;

接下来 t


行每行两个整数 n,m

,如题意。

【输出】

t


行,每行一个数,为 (nm)mod10007

的答案。

【输入样例】

4
5 1
5 2
7 3
4 2

【输出样例】

5
10
35
6

【提示】

数据范围与提示:

对于全部数据,1≤t≤200,1≤m≤n≤2×108

这道题没有什么含金量但是题目本身很神♂奇

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline ll power(ll a,ll b)
{
ll res=;
while(b)
{
if(b&) res=res*a%mod; a=a*a%mod; b>>=;
}
return res;
}
inline ll C(ll n,ll m)
{
ll n0=,m0=;
for(ll i=n-m+;i<=n;i++) n0=n0*i%mod;
for(ll i=;i<=m;i++) m0=m0*i%mod;
return n0*power(m0,mod-)%mod;
}
inline ll Lucas(ll n,ll m)
{
if(m==) return ;
return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main()
{
int t;
t=read();
ll n,m;
while(t--)
{
n=(ll)read();
m=(ll)read();
printf("%lld\n",Lucas(n,m));
}
return ;
}

1656:Combination的更多相关文章

  1. 【BZOJ】1656:[Usaco2006 Jan]The Grove 树木(bfs+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1656 神bfs! 我们知道,我们要绕这个联通的树林一圈. 那么,我们想,怎么才能让我们的bfs绕一个 ...

  2. 数字组合问题:Combination,CombinationSum,CombinationSum2,CombinationSum3

    Combination问题描述:给定n和k,找出1-n之间所有k个数的组合,例如:n=3,k=2,返回 [[1,2]  [1,3]  [2,3]] 算法分析:利用递归.递归边界就是curr.size( ...

  3. LeetCode OJ:Combination Sum II (组合之和 II)

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  4. LeetCode OJ:Combination Sum (组合之和)

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  5. LeetCode OJ:Combination Sum III(组合之和III)

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  6. 540A: Combination Lock

    题目链接:http://codeforces.com/problemset/problem/540/A 题意: 输入的两个长度一样的数,求对应位置的某位数到下一个数需要最小的步长,每次只能先前或先后走 ...

  7. 一本通1656Combination

    1656:Combination 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自:BZOJ 2982 LMZ 有 n 个不同的基友,他每天晚上要选  ...

  8. [LeetCode] Combination Sum IV 组合之和之四

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  9. [LeetCode] Combination Sum III 组合之和之三

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

随机推荐

  1. SQL Server系统函数:元数据函数

    原文:SQL Server系统函数:元数据函数 1.列的长度.列名 --列的长度 select COL_LENGTH('dbo.wct', --表名 'wcid') --列名 --列名 select ...

  2. c#获取本月有哪些周六、周日

    最近项目中有用到本月所有的周六,周日,特此分享一下! 算法思路:写一个循环,条件为本月开始日期.本月截至日期,通过循环获取第一个周六,加一天就是周日,每增加六天就是下一个周六,依次类推,循环到月末 代 ...

  3. Python练习_购物车_day6

    第一次代码 (1) 输出商品列表,用户输入序号,显示用户选中的商品. 页面显示 序号 + 商品名称,如: 1 手机 2 电脑 (2): 用户输入选择的商品序号,然后打印商品名称 (3):如果用户输入的 ...

  4. AI 公司与比赛

    科大讯飞 网站:https://www.iflytek.com/ 比赛:http://challenge.xfyun.cn/2019/ AI 大学:https://www.aidaxue.com/ 华 ...

  5. java 传入用户名和密码并自动提交表单实现登录到其他系统

    不用单点登录,模拟远程项目的登录页面表单,在访问这个页面的时候自动提交表单到此项目的登录action,就可以实现登录到其他系统. ssh框架项目 1.以下是本地系统的action代码: import ...

  6. Go map使用

    前言 map 是在 Go 中将值(value)与键(key)关联的内置类型.通过相应的键可以获取到值. 在一个map里所有的键都是唯一的,而且必须是支持==和!=操作符的类型,切片.函数以及包含切片的 ...

  7. nginx的so_keepalive和timeout相关小计

    KeepAlive 这里的keepalive是TCP的探活机制: [root@ ~]# sysctl -a |grep tcp_keepalive net.ipv4.tcp_keepalive_tim ...

  8. B+树Java代码实现以及测试

    M阶B+树的定义: 任意非叶子结点最多有M个子节点:且M>2: 除根结点以外的非叶子结点至少有 M/2个子节点: 根结点至少有2个子节点: 除根节点外每个结点存放至少M/2和至多M个关键字:(至 ...

  9. 【Hibernate】 二级缓存及查询缓存

    一.Hibernate的二级缓存 1.1 类缓存区特点 缓存的是对象的散装的数据. 图一 Hibernate的二级缓存的散装数据 1.2 集合缓存区的特点: 缓存的是对象的id.需要依赖类缓冲区的配置 ...

  10. json —— pickle 的序列化和反序列化

    前言json的序列化和反序列化 1, json 只能序列化简单的数据类型,如,列表,字典,字符串,等简单的类型,不能序列化复杂的类型. 2, json 是支持所有的语言的,多以我们跨语言的时候都是用j ...