A---Hard to prepare ACM-ICPC 2018 徐州赛区网络预赛

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lpeaceminusone/article/details/82721321

After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle.

There are N guests Reimu serves. Kokoro has 2^k2k masks numbered from 0,1,\cdots,0,1,⋯, 2^k - 12k−1, and every guest wears one of the masks. The masks have dark power of Dark Nogaku, and to prevent guests from being hurt by the power, two guests seating aside must ensure that if their masks are numbered ii and jj , then ii XNOR jj must be positive. (two guests can wear the same mask). XNOR means ~(ii^jj) and every number has kk bits. (11 XNOR 1 = 11=1, 00 XNOR 0 = 10=1, 11 XNOR 0 = 00=0)

You may have seen 《A Summer Day's dream》, a doujin Animation of Touhou Project. Things go like the anime, Suika activated her ability, and the feast will loop for infinite times. This really troubles Reimu: to not make her customers feel bored, she must prepare enough numbers of different Nogaku scenes. Reimu find that each time the same guest will seat on the same seat, and She just have to prepare a new scene for a specific mask distribution. Two distribution plans are considered different, if any guest wears different masks.

In order to save faiths for Shrine, Reimu have to calculate that to make guests not bored, how many different Nogaku scenes does Reimu and Kokoro have to prepare. Due to the number may be too large, Reimu only want to get the answer modules 1e9+71e9+7 . Reimu did never attend Terakoya, so she doesn't know how to calculate in module. So Reimu wishes you to help her figure out the answer, and she promises that after you succeed she will give you a balloon as a gift.

Input

First line one number TT , the number of testcases; (T \le 20)(T≤20) .

Next TT lines each contains two numbers, NN and k(0<N, k \le 1e6)k(0<N,k≤1e6) .

Output

For each testcase output one line with a single number of scenes Reimu and Kokoro have to prepare, the answer modules 1e9+71e9+7 .

样例输入复制

2
3 1
4 2

样例输出复制

2
84

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define mem(a,b) memset(b,sizeof(a),b)
#define ll long long
#define inf 0x3f3f3f
using namespace std;
#define mod 1000000007
const int maxn=1000115;
ll pow(ll n,ll m){
    ll ans=1;
    while(m){
        if(m%2)ans=(ans*n)%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ans;
}
ll a[maxn]={1};
ll sum(ll n,ll m){
   ll ans;
   if(n==1)
        return a[m];
   if(n==2)
        return a[m]*(a[m]-1)%mod;
   ans=(a[m]*pow(a[m]-1, n-2)%mod*(a[m]-2)%mod+sum(n-2, m))%mod;
   return ans;
}
int main(){
    a[0]=1;
    for(int i=1;i<=1000000;i++)
    a[i]=(a[i-1]*2)%mod;
    int t;
    scanf("%d",&t);
    while(t--){
        ll n,m;
        scanf("%lld%lld",&n,&m);
        printf("%lld\n",sum(n,m)%mod);
    }
}

猜你喜欢

转载自blog.csdn.net/lpeaceminusone/article/details/82721321