a, b and limit. Find every integer not greater than limit that can be written as a^i + b^j for some integers i ≥ 0 and j ≥ 0.
Each such number must appear in the answer exactly once, even if it can be formed in several ways. The numbers may be returned in any order.a=2, b=5, limit=12 → [2, 3, 5, 6, 7, 9]
2 = 1 + 1, 3 = 2 + 1, 5 = 4 + 1, 6 = 1 + 5, 7 = 2 + 5, 9 = 8 + 1 = 4 + 5. The sum 9 can be made two ways but appears in the answer once.
a=1, b=4, limit=20 → [17, 2, 5]
Every power of 1 is 1, so only 1 + 1, 1 + 4 and 1 + 16 qualify.
a=7, b=3, limit=1 → []
a, b ≤ 100limit ≤ 10⁶a=2, b=5, limit=12
[2, 3, 5, 6, 7, 9]
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.