码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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. }

  • 相关阅读:
    pytest fixture 中的使用包信scope skip conftest.py 和参数化等功能使用
    Openharmony轻量系统实验--GPIO点灯
    uniapp onPageScroll监听页面滚动不起作用?解决方案
    JVM学习笔记——内存结构篇
    一文带你深入了解JVM性能调优以及对JVM调优的全面总结
    Mac M1通过homebrew安装Redis报错(perl: unknown or unsupported macOS version: :dunno)
    网络安全(黑客)自学
    淘宝/天猫获得淘宝店铺详情 API 返回值说明(seller_info-获得淘宝店铺详情)
    如果不知道这4种缓存模式,敢说懂缓存吗?
    数据分析-numpy
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/125406378
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号