File tree Expand file tree Collapse file tree
C++17/백준/Bronze/2721. 삼각수의 합 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # [ Bronze III] 삼각수의 합 - 2721
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/2721 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 2024 KB, 시간: 0 ms
8+
9+ ### 분류
10+
11+ 수학, 구현
12+
13+ ### 제출 일자
14+
15+ 2026년 2월 21일 21:22:26
16+
17+ ### 문제 설명
18+
19+ <p >n번째 삼각수, T(n)은 1부터 n까지의 합이다. T(n) = 1 + ... + n. 이것은 삼각형 모양으로 표현할 수 있다. 아래 그림은 T(4)를 나타낸 것이다.</p >
20+
21+ <p ><img alt =" " src =" https://www.acmicpc.net/upload/images/tsum.png " style =" height :90px ; width :87px " ></p >
22+
23+ <p >다음과 같은 식을 통해 가중치를 부여한 삼각수의 합을 구할 수 있다.</p >
24+
25+ <p >W(n) = Sum[k=1..n; k*T(k+1)]</p >
26+
27+ <p >n이 주어졌을 때, W(n)을 구하는 프로그램을 작성하시오.</p >
28+
29+ ### 입력
30+
31+ <p >첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 정수 n 하나로 이루어져 있다. (1<=n<=300)</p >
32+
33+ ### 출력
34+
35+ <p >각 테스트 케이스에 대해 W(n)을 한 줄에 하나씩 출력한다.</p >
36+
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ using namespace std ;
3+
4+ const int N = 301 ;
5+ int t[N + 1 ];
6+ int w[N + 1 ];
7+
8+ int main () {
9+ ios::sync_with_stdio (0 );
10+ cin.tie (0 );
11+ cout.tie (0 );
12+
13+ for (int i = 1 ; i <= N; ++i) t[i] = t[i - 1 ] + i;
14+ for (int i = 1 ; i < N; ++i) {
15+ w[i] = w[i - 1 ] + i * t[i + 1 ];
16+ }
17+
18+ int q; cin >> q;
19+ while (q--) {
20+ int i; cin >> i;
21+ cout << w[i] << " \n " ;
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments