当前位置: 代码迷 >> 综合 >> HDOJ 2502 月之数
  详细解决方案

HDOJ 2502 月之数

热度:70   发布时间:2023-10-21 18:39:45.0

HDACM 2502

找规律

import java.util.Scanner;public class Main {public static void main(String[] args) {int moonNum[] = new int[21];moonNum[1] = 1;for (int i = 2; i < moonNum.length; i++) {moonNum[i] = moonNum[i-1]*2+(int)Math.pow(2, i-2);}Scanner sc = new Scanner(System.in);int t = sc.nextInt();while(t-->0){int n = sc.nextInt();System.out.println(moonNum[n]);}sc.close();}
}