2013 Multi-University Training Contest 1 Partition

这题主要是推公式……

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
ll mod=1000000007;
ll pows(ll a,ll b)
{

    ll ans=1;
    while
(b)
    {

        if
(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }

    return
ans;
}

int
main()
{

    int
t;
    ll ans,n,k,m;
    cin>>t;
    while
(t--)
    {

        scanf("%I64d%I64d",&n,&k);
        m=n-k+1;
        if
(n<k) ans=0;
        else if
(m==1) ans=1;
        else if
(m==2) ans=2;
        else

        {

            ans=(m+2)*pows(2,m-3)%mod;
            if
(ans<0) ans=(ans%mod+mod)%mod;
        }

        printf("%I64d\n",ans);
    }

    return
0;
}

posted @ 2013-07-24 18:58  _随心所欲_  阅读(148)  评论(0编辑  收藏  举报