炫酷数学

链接:https://ac.nowcoder.com/acm/contest/331/J
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个。

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

当然,(A=1,B=0)和(A=0,B=1)被认为是不同的二元组。
输入描述:
第一行输入一个非负整数M。

N

2
M
,
M

100
N=2M,M≤100

即2的M次为N。
输出描述:
一个整数ans,对998244353取模。
示例1
输入
复制
0
输出
复制
1
示例2
输入
复制
71
输出
复制
588378066

思路:能看出是3的快速幂就行了

AC代码:

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        BigInteger n=new BigInteger("3");
        Scanner sc = new Scanner(System.in);
        int m=sc.nextInt();
        n=n.pow(m);
        BigInteger mod=new BigInteger("998244353");
        System.out.println(n.mod(mod));
        sc.close();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42105744/article/details/87086967