<p>Given three integers <code>x</code>, <code>y</code>, and <code>bound</code>, return <em>a list of all the <strong>powerful integers</strong> that have a value less than or equal to</em> <code>bound</code>.</p>

<p>An integer is <strong>powerful</strong> if it can be represented as <code>x<sup>i</sup> + y<sup>j</sup></code> for some integers <code>i &gt;= 0</code> and <code>j &gt;= 0</code>.</p>

<p>You may return the answer in <strong>any order</strong>. In your answer, each value should occur <strong>at most once</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> x = 2, y = 3, bound = 10
<strong>Output:</strong> [2,3,4,5,7,9,10]
<strong>Explanation:</strong>
2 = 2<sup>0</sup> + 3<sup>0</sup>
3 = 2<sup>1</sup> + 3<sup>0</sup>
4 = 2<sup>0</sup> + 3<sup>1</sup>
5 = 2<sup>1</sup> + 3<sup>1</sup>
7 = 2<sup>2</sup> + 3<sup>1</sup>
9 = 2<sup>3</sup> + 3<sup>0</sup>
10 = 2<sup>0</sup> + 3<sup>2</sup>
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> x = 3, y = 5, bound = 15
<strong>Output:</strong> [2,4,6,8,10,14]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= x, y &lt;= 100</code></li>
	<li><code>0 &lt;= bound &lt;= 10<sup>6</sup></code></li>
</ul>

from typing import List

class Solution:
    def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
        powerful_ints = set()
        
        # Start with i = 0 and j = 0
        i = 0
        while True:
            # Calculate x^i
            x_power = x ** i
            if x_power > bound:
                break
            
            j = 0
            while True:
                # Calculate y^j
                y_power = y ** j
                result = x_power + y_power
                
                if result > bound:
                    break
                
                powerful_ints.add(result)
                
                # If y is 1, y^j will always be 1 for j >= 1, so break to avoid infinite loop
                if y == 1:
                    break
                
                j += 1
            
            # If x is 1, x^i will always be 1 for i >= 1, so break to avoid infinite loop
            if x == 1:
                break
            
            i += 1
        
        return list(powerful_ints)

# Example usage:
# sol = Solution()
# print(sol.powerfulIntegers(2, 3, 10))  # Output: [2, 3, 4, 5, 7, 9, 10]
# print(sol.powerfulIntegers(3, 5, 15))  # Output: [2, 4, 6, 8, 10, 14]
16200