题目链接:

A Boring Question

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)

Problem Description
There are an equation.
∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?
We define that (kj+1kj)=kj+1!kj!(kj+1−kj)! . And (kj+1kj)=0 while kj+1<kj.
You have to get the answer for each n and m that given to you.
For example,if n=1,m=3,
When k1=0,k2=0,k3=0,(k2k1)(k3k2)=1;
Whenk1=0,k2=1,k3=0,(k2k1)(k3k2)=0;
Whenk1=1,k2=0,k3=0,(k2k1)(k3k2)=0;
Whenk1=1,k2=1,k3=0,(k2k1)(k3k2)=0;
Whenk1=0,k2=0,k3=1,(k2k1)(k3k2)=1;
Whenk1=0,k2=1,k3=1,(k2k1)(k3k2)=1;
Whenk1=1,k2=0,k3=1,(k2k1)(k3k2)=0;
Whenk1=1,k2=1,k3=1,(k2k1)(k3k2)=1.
So the answer is 4.
 
Input
The first line of the input contains the only integer T,(1≤T≤10000)
Then T lines follow,the i-th line contains two integers n,m,(0≤n≤109,2≤m≤109)
 
Output
 
For each n and m,output the answer in a single line.
 
Sample Input
 
2
1 2
2 3
 
Sample Output
 
3
13
 
题意:
 
就是求这个式子的值是多少;
 
思路:
 
∑(km,km-1)(km-1,km-2)...(k2,k1)=∑(km,km-1)...(k3,k2)(∑(k2,k1){0<=k1<=k2})=∑(km,km-1)...∑(k3,k2)*2k2 
∑(k3,k2)*2k2 =(1+2)k3;二项式定理,以后也是这样,最后得到的结果为(mn+1-1)/(m-1);
 
AC代码:
 
/************************************************
┆ ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓   ┏━┛ ┆
┆  ┃   ┃  ┆      
┆  ┃   ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃    ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+10;
const int maxn=2e3+14;
const double eps=1e-12; LL pow_mod(LL x,LL y)
{
LL s=1,base=x;
while(y)
{
if(y&1)s=s*base%mod;
base=base*base%mod;
y>>=1;
}
return s;
} int main()
{
int t;
read(t);
while(t--)
{
LL n,m;
read(n);read(m);
cout<<(pow_mod(m,n+1)-1+mod)%mod*pow_mod(m-1,mod-2)%mod<<"\n";
}
return 0;
}

  

hdu-5793 A Boring Question(二项式定理)的更多相关文章

  1. HDU 5793 - A Boring Question

    HDU 5793 - A Boring Question题意: 计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1]  ) % 1000000007=? (C[ ...

  2. HDU 5793 A Boring Question (找规律 : 快速幂+逆元)

    A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...

  3. HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. hdu 5793 A Boring Question(2016第六场多校)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. HDU 5793 A Boring Question 多校训练

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1 ...

  7. HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)

    参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...

  8. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

  9. 多校6 1001 HDU5793 A Boring Question (推公式 等比数列求和)

    题解:http://bestcoder.hdu.edu.cn/blog/ 多校6 HDU5793 A Boring Question // #pragma comment(linker, " ...

随机推荐

  1. Log4net日志记录、详细配置(自己使用>)

    log4net库是Apache log4j框架在Microsoft.NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具 1.首先添加对log4net.dll的引 ...

  2. DCDC电路电感和电容啸叫的原因

    电感啸叫原因 如果耳朵能听到啸叫(吱吱声),可以肯定电感两端存在一个20HZ-20KHZ(人耳范围)左右的开关电流. 例如DC-DC电路的电感啸叫,由于负载电流过大 DC内部有一个限流保护电路,当负载 ...

  3. mBot试用体验

    [Arduino话题] [mBot试用体验]1.mBot开箱体验(部分资料合集)http://bbs.elecfans.com/forum.php?mod=viewthread&tid=532 ...

  4. NGINX配置文件优化示例

    Nginx主配置文件 upstream.conf配置文件 # server nginx配置文件最好分开写,不要把所有的逻辑都放在一个文件里面,会看着很麻烦,,之前我的配置文件都放一起了,,导致现在维护 ...

  5. apt-mirror 校验错误文件处理

    apt-mirror是一个用来将Debian或Ubuntu的软件源镜像到本地的工具,这个工具工作得非常好,不过有的时候由于网络问题,会有一些文件的校验是失败的,但apt-mirror并不能发现,等到最 ...

  6. 通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。

    错误原因: xml文件中,本来是要配置成下面这样的: http://www.springframework.org/schema/context http://www.springframework. ...

  7. 概率图模型(PGM)学习笔记(二)贝叶斯网络-语义学与因子分解

    概率分布(Distributions) 如图1所看到的,这是最简单的联合分布案例,姑且称之为学生模型. 图1 当中包括3个变量.各自是:I(学生智力,有0和1两个状态).D(试卷难度,有0和1两个状态 ...

  8. 深入Asyncio(十二)Asyncio与单元测试

    Testing with asyncio 之前有说过应用开发者不需要将loop当作参数在函数间传递,只需要调用asyncio.get_event_loop()即可获得.但是在写单元测试时,可能会需要用 ...

  9. 12 nginx URL 重写 ecshop案例

    一:URL 重写 ecshop案例 Rewrite语法 Rewrite 正则表达式 定向后的位置 模式 Goods-3.html ---->Goods.php?goods_id=3 goods- ...

  10. 32.10 使用模板更改控件的UI

    32.10  使用模板更改控件的UI 样式是改变WPF控件基本外形的非常好(且非常简单)的方式,它通过为窗口部件的特性设置建立一组默认的值,从而改变WPF控件的基本外形.但是,即使样式允许我们改变各种 ...