Find a Safe Pair of Log Token IDs
Context
A document-processing service assigns consecutive integer IDs to tokens in a diagnostic log. Given the smallest and largest allowed IDs, find two different IDs whose least common multiple is also an allowed ID. The service needs a direct construction rather than a search through all token-ID pairs.
Problem
Given an inclusive interval from lower_id to upper_id, return two distinct integers from that interval whose least common multiple is within the same interval. If such a pair cannot exist, return an empty list.
Use the constant-time construction based on the lower endpoint and its double. When the double is no greater than the upper endpoint, return [lower_id, 2 * lower_id]. Otherwise, return []. The endpoints are inclusive, and the returned pair must be ordered from smaller to larger value.
Examples
lower_id = 3upper_id = 8[3, 6]lower_id = 7upper_id = 10[]lower_id = 5upper_id = 10[5, 10]Constraints
1 <= lower_id <= 1000000000lower_id <= upper_id <= 2000000000- Types:
lower_idis int,upper_idis int; result is int[]
Function signature
def find_log_token_pair(lower_id: int, upper_id: int) -> list[int]
lower_idint- The smallest allowed token ID.
upper_idint- The largest allowed token ID.
- returns list[int]
- The constructed pair in increasing order, or an empty list when the interval cannot contain a valid pair.
Adapted from MBPP problem task_177 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- An empty list is the designated failure result.
- The least common multiple of n and 2n is 2n for every positive n.