牛客寒假5-J.炫酷数学

链接:https://ac.nowcoder.com/acm/contest/331/J

题意:

小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个。

当然,直接做这个式子对小希来说太难了,所以小希改变了一些条件,她仅想知道其中A,B<NA,B<N的情况,其中N为2的幂次。

当然,(A=1,B=0)和(A=0,B=1)被认为是不同的二元组。

思路:

对于每个二进制,0-0,1-0,0-1,即可。

快速幂。

代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int MOD = 998244353;

LL Quick_Mi(int m)
{
    LL x = 3;
    LL res = 1;
    while (m > 0)
    {
        if (m&1)
            res = res * x % MOD;
        x = x * x % MOD;
        m >>= 1;
    }
    return res;
}

int main()
{
    int m;
    cin >> m;
    cout << Quick_Mi(m) << endl;

    return 0;
}

  

原文地址:https://www.cnblogs.com/YDDDD/p/10353801.html