970. Powerful Integers

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 970

class Solution:
    def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
        res = set()
        a = 1
        while a <= bound:
            b = 1
            while a + b <= bound:
                res.add(a + b)
                b *= y
                if y == 1:
                    break
            if x == 1:
                break
            a *= x
        return list(res)