백준 #2721번 삼각수의 합

jhj·2024년 5월 12일

백준 JAVA

목록 보기
463/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int testCase = sc.nextInt();
		for(int i = 0; i < testCase; i++) {
			int n = sc.nextInt();
			int[] t = new int[n + 1];
			int[] T = new int[n + 1];
			int W = 0;
			
			for(int j = 0; j <= n; j++) {
				t[j] = j + 1;
			}
			
			for(int j = 0; j <= n; j++) {
				T[j] = 0;
			}
			
			for(int j = 0; j <= n; j++) {
				for(int k = 0; k <= j; k++) {
					T[j] += t[k];
				}
			}
			
			for(int j = 0; j <= n; j++) {
				W += j * T[j];
			}

			System.out.println(W);
		}
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글