File: count-distinct-numbers-on-board/solution.py

Date: 2026-06-06

Time: 15:56

Purpose

This file solves LeetCode 2549: Count Distinct Numbers on Board. The problem places a number n on a board; every day for 10^9 days, for every x on the board, any i in [1, n] where x % i == 1 is also placed on the board. The function returns how many distinct numbers end up on the board.

Key Components

distinct_numbers(n: int) -> int — The sole function. Returns 1 if n == 1, otherwise n - 1.

Patterns

Mathematical reduction. This is a pure-math O(1) solution that avoids simulating 10^9 days. The insight:

The entire simulation collapses to a ternary expression. This pattern of recognizing steady-state behavior without simulation is common in competitive programming.

Dependencies

Imports: None — pure arithmetic, no standard library needed.

Imported by: count-distinct-numbers-on-board/test_solution.py (the "Imported By" list in the prompt is an artifact of the repo's shared test harness; only the co-located test file actually imports this solution's function).

Flow

Single expression evaluation: check n == 1, branch to 1 or n - 1. No loops, no data structures, no state.

Invariants

Error Handling

None. The function trusts the caller to provide valid input per the problem constraints. No validation, no exceptions.

Topics to Explore

Beliefs