Powerful Integers - Problem

Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.

An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.

You may return the answer in any order. In your answer, each value should occur at most once.

Input & Output

Example 1 — Basic Case
$ Input: x = 2, y = 3, bound = 10
Output: [2,3,4,5,10]
💡 Note: Powers of 2: [1,2,4,8], Powers of 3: [1,3,9]. Valid sums ≤ 10: 1+1=2, 2+1=3, 1+3=4, 2+3=5, 1+9=10
Example 2 — Edge Case x=1
$ Input: x = 1, y = 2, bound = 5
Output: [2,3,5]
💡 Note: x=1 means x^i=1 for all i. Powers of 2: [1,2,4]. Valid sums: 1+1=2, 1+2=3, 1+4=5
Example 3 — Small Bound
$ Input: x = 3, y = 5, bound = 15
Output: [2,4,6,8,14]
💡 Note: Powers of 3: [1,3,9], Powers of 5: [1,5]. Valid sums ≤ 15: 1+1=2, 3+1=4, 1+5=6, 3+5=8, 9+5=14

Constraints

  • 1 ≤ x, y ≤ 100
  • 0 ≤ bound ≤ 106

Visualization

Tap to expand
Powerful Integers: x=2, y=3, bound=10Find all x^i + y^j ≤ boundx^0 = 1x^1 = 2x^2 = 4x^3 = 8y^0 = 1y^1 = 3y^2 = 9Valid Combinations (sum ≤ 10):1+1=2, 2+1=3, 1+3=4, 2+3=5, 1+9=10Output: [2, 3, 4, 5, 10]
Understanding the Visualization
1
Input
Given x=2, y=3, bound=10
2
Generate Powers
x powers: [1,2,4,8], y powers: [1,3,9]
3
Find Valid Sums
All combinations ≤ 10: [2,3,4,5,10]
Key Takeaway
🎯 Key Insight: Powers grow exponentially, limiting the search space to at most log(bound) values for each base
Asked in
Google 25 Facebook 18 Amazon 15
28.5K Views
Medium Frequency
~15 min Avg. Time
485 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen