작성일 :

문제 링크

15236번 - Dominos

설명

크기 n인 도미노 세트의 전체 점수 합을 구하는 문제입니다.


접근법

0부터 n까지의 점이 두 면에 조합된 모든 타일의 점수 합입니다.

공식 n(n+1)(n+2)/2로 계산할 수 있습니다.


Code

C#

1
2
3
4
5
6
7
8
9
using System;

class Program {
  static void Main() {
    var n = long.Parse(Console.ReadLine()!);
    var ans = n * (n + 1) * (n + 2) / 2;
    Console.WriteLine(ans);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  if (!(cin >> n)) return 0;
  ll ans = n * (n + 1) * (n + 2) / 2;
  cout << ans << "\n";

  return 0;
}