Dowemo

In the table below, the rule is

( 1 - m^ ( n + 1 )/( 1 );









#include <iostream>


#include <cstdio>


#include <cstring>


#include <cmath>


#include <algorithm>


#include <vector>


using namespace std;


typedef long long ll;


const ll mod=1000000007;


ll quick(ll n,ll m)


{


 ll res=1;


 while(m)


 {


 if(m&1)


 res=res*n%mod;


 m>>=1;


 n=n*n%mod;


 }


 return res;


}



int main()


{


 int t;


 scanf("%d",&t);


 while(t--)


 {


 ll n,m;


 scanf("%lld%lld",&n,&m);


 ll ans=0;


 ans=quick(m,n+1);


 ans=ans-1;


 ll res=quick(m-1,mod-2);


 ans=ans*res%mod;


 printf("%lldn",ans);


 }


}


/*


LL e[510][510];


void C(){


 for(int i=0;i<510;i++)


 e[i][0]=1;


 for(int i=1;i<510;i++)


 for(int j=1;j<510;j++)


 e[i][j]=(e[i-1][j-1]+e[i-1][j])%mod;


}



int n,m,ans;


vector<int>vec;


void tt(int ced,int fir)


{


 if(ced==m)


 {


 int tmp=1;


 for(int i=1;i<vec.size();i++)


 tmp*=e[vec[i]][vec[i-1]];


 ans+=tmp;


 return ;


 }


 for(int i=fir;i<=n;i++)


 {


 vec.push_back(i);


 tt(ced+1,fir);


 vec.pop_back();


 }


}


int main( )


{



 C();


 for(n=0; n<=5; n++) {


 for(m=2; m<=5; m++) {


 ans = 0;


 vec.clear();


 tt(0,0);


 printf("%d-%d : %d =======", n,m,ans);


 }


 printf("n");


 }



 return 0;


}


*/











Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs