hdu 5793A Boring Question (打表 + 乘法逆元 + 快速模)
来源:互联网 发布:网络招标注册流程 编辑:程序博客网 时间:2024/05/16 23:47
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
#include <set>#include <map>#include <stack>#include <queue>#include <deque>#include <cmath>#include <vector>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define L(i) i<<1#define R(i) i<<1|1#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-9#define maxn 10010#define MOD 1000000007#define LL long longint T;LL n,m;const LL mod =1000000007;//int a[15];//int ff[10];//int ans;////int solve(int num)//{// int tot=0;// if(num==0) return 0;// while(num)// {// a[tot++] = num%10;// num /=10;// }// if(a[tot-1]<a[0]) return 0;// int ans=ff[a[tot-1] - a[0]];// int re=ff[a[0]];//// for(int i=0;i<tot;i++)// {// if(a[i]<a[i-1]) return 0;// else// {// int c=a[i] - a[i-1];// re *=ff[c];// }// }// return ans / re;//}////void dfs(int n,int len,int re)//{// printf("%d\n",re);// if(len==0)// {// int cc=solve(re);// ans +=cc;// return ;// }// for(int i=0;i<=n;i++)// dfs(n,len-1,re*10 + i);//}////void init()//{// ff[0]=0;// for(int i=1;i<=10;i++)// ff[i] = ff[i-1] * i;//// for(int n=0; n<=9; n++)// for(int m=2; m<=5; m++)// {// ans=0;// dfs(n,m,0);// printf("dp[%d][%d]=%d\n", n,m,ans);// }//}LL inv(LL a,LL m){ if(a==1) return 1; return inv(m%a,m) * (m-m/a) %m;}LL pow_m(LL a,LL b,LL m){ LL ans=1; while(b) { if(b&1) { ans = ans * a%m; } a = a*a%m; b>>=1; } return ans;}int main(){ init(); scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&n,&m); LL ans = (pow_m(m,n+1,mod) - 1 + mod) %mod * inv(m-1,mod) % mod; printf("%I64d\n",ans); } return 0;}
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
0 0
- hdu 5793A Boring Question (打表 + 乘法逆元 + 快速模)
- HDU 5793 A Boring Question(逆元+快速幂)
- hdu 5793 A Boring Question (数学 + 快速幂 + 乘法逆元)
- HDU 5793 A Boring Question (快速幂 + 乘法逆元 + 费马小定理)
- HDU 5793 A Boring Question【快速幂+逆元】
- HDU 5793 A Boring Question (逆元)
- Hdu 5793 A Boring Question【暴力打表+找规律+求逆元+快速幂+快速积】
- HDU 5793 A Boring Question(快速幂+求逆元)
- HDU 5793 A Boring Question(快速幂&求逆元)
- HDOJ 5793 A Boring Question(快速幂+逆元+数学推导)
- HDU5793 A Boring Question (快速幂,逆元)
- HDU 5793 A Boring Question (数学)
- HDU 5793 A Boring Question(数论)
- 【HDU】5793 A Boring Question
- hdu5793——A Boring Question(快速幂+逆元)
- HDU-5793 A Boring Question(矩阵快速幂)
- HDU 5793 A Boring Question (找规律+快速幂)
- A Boring Question HDU
- C++primer plus第7-8章函数笔记
- 性能优化的十个建议
- python dataframe中找出月末日期
- HDU 3879 Base Station 最大权闭合图
- hadoop2.7.2的安装过程
- hdu 5793A Boring Question (打表 + 乘法逆元 + 快速模)
- HDU 5795 A Simple Nim (打表找规律)
- 使用Intent传递自定义对象
- 安卓开发起始页面+引导页+进入主程序
- 分库后的分页处理
- Android开发03_Intent跳转
- Android 高仿微信语音聊天页面高斯模糊效果
- Jquery学习总结(3)——Jquery获取当前城市的天气信
- 08.05