一本通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. Session共享问题---理论

    随着网站访问量增加,初期的一台服务器已经完全不能支持业务,这个时候我们就需要增加服务器设备,来抗住请求的增量,如下所示: 负载均衡的目的本来就是要为了平均分配请求,所以没有固定第一次访问和第二次访问的 ...

  2. SpringCloud Hystrix/Feign 整合 Hystrix 后首次请求失败解决方案

  3. 利用Filter和HttpServletRequestWrapper实现请求体中token校验

    先说一下项目的背景,系统传参为json格式,token为其中一个必传参数,此时如果在过滤器中直接读取request,则后续controller中通过RequestBody注解封装请求参数是会报stre ...

  4. CSS 样式表{二}

    1 选择器的优先级 选择器的优先主要考虑选择器的权重 可以将各种选择器的权重以数值来表示,数值越大,优先级越高 选择器 权重值 标签selector 1 类选择器 10 ID选择器 100 行内样式 ...

  5. 如何解决Win10不能新建项目的问题?

    在Win10系统中,我们有时候会遇到右键菜单中没有新建项的情况,这时我们就无法进行文件的新建,非常耽误我们使用电脑.下面雨后清风就来分享一下Win10系统右键菜单没有新建项的解决方法. Win10系统 ...

  6. MySQL数据库的二进制安装、源码编译和基础入门操作

    一.MySQL安装 (1)安装方式: 1 .程序包yum安装 优点:安装快,简单 缺点:定死了各个文件的地方,需要修改里边的相关配置文件,很麻烦 2 .二进制格式的程序包:展开至特定路径,并经过简单配 ...

  7. sed & awk 概述

    概述 一般情况下,从grep到sed和awk的学习过程是很自然的.sed和awk是一般用户.程序员和系统管理员们处理文本文件的有力工具. sed的名字来源于其功能,它是个字符流编辑器(stream e ...

  8. Linux学习之六-Linux系统的基础优化

    Linux系统的基础优化 何谓'优化'.顾名思义,优化就是采取某些措施使某个东西或者某事物变得更加优异,出色.对于Linux而言,在初期安装好系统之后,也需要对其进行一定的基础优化,可分为安全上的优化 ...

  9. mybatise 设置全局变量实例

    前言 在平时的工作中有时候是需要在配置文件中配置全局变量的,因为这些东西是不会变的,并且每个mapper都传参的话也显得有点繁琐,还好mybatis本身是支持全局变量的,今天工作中用到了,记录一下. ...

  10. PrintWriter返回乱码的分析及解决

    用response得到输出流,即response.getOuptStream(); 返回值为ServletOutputStream 对象,即JSP的out对象,要么用response得到输出对象Pri ...