Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

& -- 位运算之一,有0则0

原题链接  Problem - 1514B - Codeforces

题目

Example
input
2
2 2
100000 20
output
4
226732710

题意

t个测试样例,在每个样例中

数组有n个数,数字范围[ 0, 2- 1]

使得数组每个数&后,结果=0,并且这n个数的和要尽量大

输出有多少个这样的数组

解析

数组每个数&后,结果=0  -->每一位至少一个0

数要尽量大  -->只要这一位可以 != 0, 就为 1

先假设每个数都为2k - 1, (每个数的每一位都=1),

对于每一位有且仅有一个数=0,有n种选法.

代码

#include <iostream>

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

int main()
{
    int t; cin >> t;
    while(t --)
    {
        int n, k;
        ll res = 1;
        cin >> n >> k;
        while(k--)
            res = res*n%mod;
        cout << res << endl;
    }
    return 0;    
}

补充

     ---- 一个难一点的&运算 Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400 - la-la-wanf - 博客园 (cnblogs.com)

原文地址:https://www.cnblogs.com/la-la-wanf/p/14718322.html