hdu5793 A Boring Question(推公式or迷之找规律)
来源:互联网 发布:矩阵和伴随矩阵的秩 编辑:程序博客网 时间:2024/05/09 23:50
思路:比赛时候是迷之手玩了很多个样例然后大胆猜测了一发公式...
正解:
A Boring Question
∑0≤k1,k2,⋯km≤n∏1≤j<m(kjkj+1) =∑0≤k1≤k2≤⋯≤km≤n∏1≤j<m(kjkj+1) =∑km=0n∑km−1=0km⋯∑k1=0k2∏1≤j<m(kjkj+1) =∑km=0n{(km−1km)∑km−1=0km{(km−2km−1)⋯∑k1=0k2(k1k2)}} =∑km=0n{(km−1km)∑km−1=0km{(km−2km−1)⋯∑k1=0k2(k1k2)}} =∑km=0n{(km−1km)∑km−1=0km{(km−2km−1)⋯∑k2=0k3(k2k3)2k2}} =∑km=0nmkm =m−1mn+1−1
#include<bits/stdc++.h>using namespace std;const int mod = 1e9+7;#define LL long longtemplate<class T1,class T2>T1 quick_mod(T1 t,T2 n){T1 ans=1;while(n){if(n&1) ans=ans*t%mod;t=t*t%mod;n>>=1;}return ans;}LL Inv(LL x){return quick_mod(x, mod-2);}int main(){ int T;scanf("%d",&T);while(T--){LL n,m;scanf("%lld%lld",&n,&m);if(n==0){printf("1\n");continue;}LL inv = Inv(m-1);LL ans = ((quick_mod(m,n+1)-1)*inv)%mod;printf("%lld\n",ans);}}
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 eachn and m that given to you.
For example,ifn=1 ,m=3 ,
Whenk1=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.
We define that
You have to get the answer for each
For example,if
When
When
When
When
When
When
When
When
So the answer is 4.
Input
The first line of the input contains the only integer T ,(1≤T≤10000)
ThenT lines follow,the i-th line contains two integers n ,m ,(0≤n≤109,2≤m≤109)
Then
Output
For each n and m ,output the answer in a single line.
Sample Input
21 22 3
Sample Output
313
Author
UESTC
Source
2016 Multi-University Training Contest 6
0 0
- hdu5793 A Boring Question(推公式or迷之找规律)
- hdu5793 A Boring Question
- HDU5793-A Boring Question
- 【HDU5793】A Boring Question(数学题)
- hdoj5793 A Boring Question【找规律】
- hdu 5793A Boring Question 推公式(多校)
- HDU 5793 A Boring Question (找规律+快速幂)
- hdu5793——A Boring Question(快速幂+逆元)
- (多校第六场1001)HDU5793 A Boring Question(逆元,等比数列和取模)
- HDU5793 A Boring Question (快速幂,逆元)
- 2016多校训练Contest6: 1001 A Boring Question hdu5793
- HDU-5793-A Boring Question(打表找规律)
- HDU 5793 A Boring Question (打表找规律)
- HDU 5793 A Boring Question(推公式+求逆元)——2016 Multi-University Training Contest 6 (1001)
- HDU 5793 A Boring Question 打表找规律
- hdu-5793 A Boring Question 打表找规律
- HDU-5793 A Boring Question(打表找规律)
- Hdu 5793 A Boring Question【暴力打表+找规律+求逆元+快速幂+快速积】
- oracle常用函数
- FB 硬件抽象层gralloc原理流程分析
- 【大话数据结构&算法】希尔排序(Java/C实现源码)
- HDU 3665 Seaside
- 二叉树中两个节点的最近公共祖先节点
- hdu5793 A Boring Question(推公式or迷之找规律)
- PhpStorm无法使用Terminal解决方法
- Maven那点事儿(Eclipse版)
- ue4 中动画控制,利用conduit节点
- JAVA学习笔记----接口、抽象类、内部类
- 【CDP-云设计模式】第6章,3.直接对象上传模式(Direct Object Upload Pattern)
- 根据前序遍历序列和中序遍历序列构造二叉树算法
- 数据结构实验:连通分量个数
- oracle数据恢复