思路:比赛时候是迷之手玩了很多个样例然后大胆猜测了一发公式...
正解:
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 long
template<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 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;
When k1=0,k2=1,k3=0,(k2k1)(k3k2)=0;
When k1=1,k2=0,k3=0,(k2k1)(k3k2)=0;
When k1=1,k2=1,k3=0,(k2k1)(k3k2)=0;
When k1=0,k2=0,k3=1,(k2k1)(k3k2)=1;
When k1=0,k2=1,k3=1,(k2k1)(k3k2)=1;
When k1=1,k2=0,k3=1,(k2k1)(k3k2)=0;
When k1=1,k2=1,k3=1,(k2k1)(k3k2)=1.
So the answer is 4.
∑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;
When k1=0,k2=1,k3=0,(k2k1)(k3k2)=0;
When k1=1,k2=0,k3=0,(k2k1)(k3k2)=0;
When k1=1,k2=1,k3=0,(k2k1)(k3k2)=0;
When k1=0,k2=0,k3=1,(k2k1)(k3k2)=1;
When k1=0,k2=1,k3=1,(k2k1)(k3k2)=1;
When k1=1,k2=0,k3=1,(k2k1)(k3k2)=0;
When k1=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)
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
Author
UESTC
Source
版权声明:本文为qq_21057881原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。