2018icpc徐州OnlineA Hard to prepare

src:https://nanti.jisuanke.com/t/31453

解答传送门

ac代码:

#include<bits/stdc++.h>
#define per(i,a,b) for(int i=a;i<=b;i++)
#define mod 1000000007
using namespace std;
typedef long long ll;
//#define int long long
const int inf =0x3f3f3f3f;
const double eps=1e-8;
int read(){
    char ch=getchar();
    int res=0,f=0;
    while(ch<'0' || ch>'9'){f=(ch=='-'?-1:1);ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+(ch-'0');ch=getchar();}
    return res*f;
}
// ------------------------head
const int siz=1000005;
int T,n,k;
ll mi[siz]={1};
ll _pow(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2==1)res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res;
}
ll fun(int a,int b){
    if(a==2)return mi[b]*(mi[b]-1)%mod;
    if(a==1)return mi[b];
    ll ans=(mi[b]*_pow(mi[b]-1,a-2)%mod*max((mi[b]-2),0ll)%mod+fun(a-2,b))%mod;
    return ans;
}
signed main()
{
    scanf("%d",&T);
    per(i,1,1000002){mi[i]=mi[i-1]*2%mod;}
    while(T--){
        scanf("%d %d",&n,&k);
        printf("%lld\n",fun(n,k)%mod);
    }

    return 0;
}

 

posted @ 2018-09-14 11:53  WindFreedom  阅读(177)  评论(0编辑  收藏  举报