백준 알고리즘 2721번 : 삼각수의 합

Zoo Da·2021년 12월 14일
0

백준 알고리즘

목록 보기
291/337
post-thumbnail

링크

https://www.acmicpc.net/problem/2721

sol1)

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;

int T(int n)
{
    return n * (n + 1) / 2;
}

int32_t main()
{
    fastio;
    int tc;
    cin >> tc;
    while (tc--)
    {
        int n, ret = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
            ret += (i * T(i + 1));
        cout << ret << "\n";
    }
}
profile
메모장 겸 블로그

0개의 댓글