nyoj 45 棋盘覆盖 【Java大数】

来源:互联网 发布:飞鹰编辑软件 编辑:程序博客网 时间:2024/05/17 03:13

先算出来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

0 0