链接:https://ac.nowcoder.com/acm/contest/1842/A
来源:牛客网
题目描述
记Ai=(00..011..1⏟)2i个1,即二进制表示下后i位为1,其余位为0的数。给定一个正整数n,求∏i=1n∏j=1nAi&A。
输出答案对998244353取模后的结果。T组数据。
输入描述:
第一行一个整数T,表示数据组数。 接下来T行每行一个整数n,含义如题目描述所示。
输出描述:
输出T行,表示每次询问的结果。
示例1
输入
2 2 4
输出
3 1250235
备注:
T≤100, 1≤n≤64。
思路:会爆long long,选用java大数。
import java.*;
import java.math.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger[] fast = new BigInteger[100];
BigInteger pos = new BigInteger("2");
BigInteger MAX=new BigInteger("998244353");
for (int i = 1; i <= 64; i++) {
fast[i] = pos.subtract(new BigInteger("1"));
pos = pos.multiply(new BigInteger("2"));
//System.out.println(fast[i]);
}
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while (T > 0) {
T--;
int n = input.nextInt();
BigInteger ans = new BigInteger("1");
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
BigInteger t = new BigInteger("1");
if (fast[i].compareTo(fast[j]) < 0)
t = fast[i];
else
t = fast[j];
ans=ans.multiply(t.mod(MAX));
ans=ans.mod(MAX);
}
}
System.out.println(ans);
}
}
}