작성일 :

문제 링크

33612번 - 피갤컵

설명

1회가 2024년 8월이고 대회가 7개월 주기로 열린다고 할 때, N번째 피갤컵이 열리는 연도와 월을 구하는 문제입니다.


접근법

기준 시점(2024년 8월)에서 (N-1)번 7개월을 더하면 됩니다. 연도/월 계산은 전체 월 수로 바꿔 계산한 뒤 다시 연도와 월로 복원하면 간단합니다.



Code

C#

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

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var total = (2024 * 12 + (8 - 1)) + (n - 1) * 7;
    var year = total / 12;
    var month = total % 12 + 1;
    Console.WriteLine($"{year} {month}");
  }
}

C++

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

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

  int n; cin >> n;
  int total = (2024 * 12 + 7) + (n - 1) * 7;
  int year = total / 12;
  int month = total % 12 + 1;
  cout << year << ' ' << month << "\n";

  return 0;
}

Tags: 33612, BOJ, C#, C++, 구현, 백준, 수학, 알고리즘

Categories: ,