cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2015 · EasyInteger arithmetic

Which Lesson Day?

National Olympiad — Municipal round (2015 season)

Submission name: lesson.cpp

Problem summary

There are six lessons each weekday, Monday through Friday. Teaching occupies calendar weeks 1–8 and 10–17; week 9 is a holiday. Lessons are numbered 1–480. Find the calendar week and weekday of a specified lesson.

Input

The lesson number n.

Output

Week w Day, using the English weekday name.

Constraints

1 ≤ n ≤ 480.

Worked example

An independently prepared example for this explanation.

Input

239

Output

Week 8 Friday

Solution analysis

  1. Change to zero-based numbering with index = n − 1. There are 30 lessons per teaching week, so index / 30 gives the number of complete teaching weeks before the lesson.
  2. Convert this to a one-based week and add one more if the result exceeds 8, skipping holiday week 9. Within a week, (index % 30) / 6 selects the weekday from Monday to Friday.
  3. For n = 239, index is 238: 238 / 30 + 1 = 8 and (238 % 30) / 6 = 4, Friday. Lesson 242 instead belongs to teaching week 9, which is calendar week 10, on Monday.

Why it works

Integer division partitions the zero-based lesson indices into consecutive blocks of 30 and then blocks of 6 within each week. These blocks exactly match teaching weeks and days. Adding the skipped calendar week after week 8 maps each teaching week to its actual week.

Complexity: O(1) time and O(1) extra space.

Watch out. Subtract one before division. Add the holiday week only after teaching week 8.

Commented C++17 solution

An independently written complete program with standard headers.

#include <iostream>
#include <string>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    // Zero-based indices align the 30-lesson weeks and six-lesson days.
    int index = n - 1;
    int week = index / 30 + 1;
    if (week > 8) {
        ++week;
    }
    const string names[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
    cout << "Week " << week << ' ' << names[(index % 30) / 6] << '\n';
    return 0;
}

Source: Arena Olimpiici ↗