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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code