• B. AND 0, Sum Big-Codeforces Round #716 (Div. 2)


    Problem - 1514B - Codeforces

    B. AND 0, Sum Big

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers nn and kk, count the number of arrays of length nn such that:

    • all its elements are integers between 00 and 2k−12k−1 (inclusive);
    • the bitwise AND of all its elements is 00;
    • the sum of its elements is as large as possible.

    Since the answer can be very large, print its remainder when divided by 109+7109+7.

    Input

    The first line contains an integer tt (1≤t≤101≤t≤10) — the number of test cases you need to solve.

    Each test case consists of a line containing two integers nn and kk (1≤n≤1051≤n≤105, 1≤k≤201≤k≤20).

    Output

    For each test case, print the number of arrays satisfying the conditions. Since the answer can be very large, print its remainder when divided by 109+7109+7.

    Example

    input

    Copy

    2
    2 2
    100000 20
    

    output

    Copy

    4
    226732710
    

    Note

    In the first example, the 44 arrays are:

    • [3,0][3,0],
    • [0,3][0,3],
    • [1,2][1,2],
    • [2,1][2,1].

    ==================================================================================================================================================

    &运算要求只要有一个是0结果一定是0,而我们如果想让结果最大,最好的方法当然是n个2^k-1,但这样与运算之后并不是0,。我们可以让n-1个数字全是2^k-1,剩下一个0,也就是k位都是0的情况。然而这k个位置是0的情况随机分配在n个数字是并不影响答案的大小的,故答案方案数就是n^k,快速幂解决即可

    1. # include<iostream>
    2. # define mod 1000000007
    3. using namespace std;
    4. typedef long long int ll;
    5. ll quickpow(ll base, ll pow)
    6. {
    7. ll ans=1;
    8. while(pow)
    9. {
    10. if(pow&1)
    11. ans=ans*base%mod;
    12. pow>>=1;
    13. base=base*base%mod;
    14. }
    15. return ans;
    16. }
    17. int main ()
    18. {
    19. int t;
    20. cin>>t;
    21. while(t--)
    22. {
    23. ll n,k;
    24. cin>>n>>k;
    25. cout<<quickpow(n,k)<<endl;
    26. }
    27. return 0;
    28. }

  • 相关阅读:
    “深入理解SpringMVC的注解驱动开发“
    Python从入门到入土-面向对象
    controller-tool的简单使用
    springboot和vue:八、vue快速入门
    神经网络-文本-图像-音频-视频基础知识
    【图像分割】图像分割质量分数,如 TP、FP、TN、FN、Accuracy、Sensitivity、Precision、MCC、Dice、Jaccard
    密码技术---密钥和SSL/TLS
    JAVA-STUDY
    PRT(Precomputed Radiance Transfer【2002】)原理实现
    qml入门教程:qml的初步使用
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/125406378