先算出来2^k*2^k 之后减去1,最后除3即可
代码:
import java.util.Scanner;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
BigInteger ans,ans1, temp, temp1, temp2;
int n, i = 0;
n = cin.nextInt();
temp = new BigInteger("2");
temp1 = new BigInteger("1");
temp2 = new BigInteger("3");
while(i < n){
int k;
k = cin.nextInt();
ans = new BigInteger("2");
int j = 2;
for(; j <= k; j ++){
ans = ans.multiply(temp);
//System.out.println(ans);
//j ++;
}
//ans = temp.pow(k);
ans = ans.multiply(ans);
//System.out.println(ans);
ans = ans.subtract(temp1);
//System.out.println(ans);
System.out.println(ans.divide(temp2));
i++;
}
}
}
题目链接:
http://acm.nyist.net/JudgeOnline/problem.php?pid=45