문제 링크입니다: www.acmicpc.net/problem/2721
2721번: 삼각수의 합
n번째 삼각수, T(n)은 1부터 n까지의 합이다. T(n) = 1 + ... + n. 이것은 삼각형 모양으로 표현할 수 있다. 아래 그림은 T(4)를 나타낸 것이다. 다음과 같은 식을 통해 가중치를 부여한 삼각수의 합을 구
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int getTn(int n) | |
{ | |
return n * (n + 1) / 2; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int T; | |
cin >> T; | |
for (int t = 0; t < T; t++) | |
{ | |
int n; | |
cin >> n; | |
int result = 0; | |
for (int i = 1; i <= n; i++) | |
{ | |
result += i * getTn(i + 1); | |
} | |
cout << result << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2741번 N 찍기 (0) | 2021.04.25 |
---|---|
백준 2739번 구구단 (0) | 2021.04.25 |
백준 2720번 세탁소 사장 동혁 (0) | 2021.04.25 |
백준 2576번 홀수 (0) | 2021.04.25 |
백준 2566번 최댓값 (0) | 2021.04.25 |