Problem · Array
Parameterized Divisibility Labels
Learn this problemProblem statement
You are given positive integers a, b, and n. For each integer i from 0 through n - 1, produce exactly one string:
"AB"ifiis divisible by bothaandb."A"ifiis divisible byaonly."B"ifiis divisible bybonly.- The decimal representation of
iotherwise.
Return the n produced strings in order.
Function
divisibilityLabels(a: int, b: int, n: int) → String[]Examples
Example 1
a = 2b = 3n = 7return = ["AB","1","A","B","A","5","AB"]0 and 6 are divisible by both divisors. The remaining positions follow the single-divisor or decimal rules.
Example 2
a = 1b = 2n = 4return = ["AB","A","AB","A"]Every number is divisible by 1, and the even positions are also divisible by 2.
Constraints
1 <= a, b <= 10^91 <= n <= 100000