> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Powerful Integers Python Solution with Tests

> Tested Python solution for LeetCode 970 with 18 pytest cases. Generate a practice environment with lcpy.

LeetCode 970, [Medium](/catalog/medium). Topics: [Hash Table](/catalog/topics/hash-table), [Math](/catalog/topics/math), [Enumeration](/catalog/topics/enumeration). [View on LeetCode](https://leetcode.com/problems/powerful-integers/description/).

Generate this problem as a practice environment: tested reference solution, 18 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 970   # by problem number
lcpy gen -s powerful_integers   # by problem name
```

## 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 `x^i + y^j` 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**.

### Examples

```
Input: x = 2, y = 3, bound = 10
Output: [2,3,4,5,7,9,10]
Explanation:
2 = 2^0 + 3^0
3 = 2^1 + 3^0
4 = 2^0 + 3^1
5 = 2^1 + 3^1
7 = 2^2 + 3^1
9 = 2^3 + 3^0
10 = 2^0 + 3^2
```

```
Input: x = 3, y = 5, bound = 15
Output: [2,4,6,8,10,14]
```

### Constraints

* 1 \<= x, y \<= 100
* 0 \<= bound \<= 10^6

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/powerful_integers/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/powerful_integers/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(log(x, bound) * log(y, bound))
    # Space: O(log(x, bound) * log(y, bound))
    def powerful_integers(self, x: int, y: int, bound: int) -> list[int]:
        def powers(base: int) -> list[int]:
            if base == 1:
                return [1] if bound >= 1 else []
            vals: list[int] = []
            val = 1
            while val <= bound:
                vals.append(val)
                val *= base
            return vals

        found: set[int] = set()
        for xi in powers(x):
            for yj in powers(y):
                total = xi + yj
                if total <= bound:
                    found.add(total)
        return list(found)
```

## Complexity

| Time | Space |
| - | - |
| O(log(x, bound) \* log(y, bound)) | O(log(x, bound) \* log(y, bound)) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.