鏈接: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);
}
}
}