to represent each integer. Programming example The example below implements the sum-product function described in the definition above to search for numbers and cycles in Python. def sum_product(x: int, b: int) -> int: """Sum-product number.""" sum_x = 0 product = 1 while x > 0: if x % b > 0: sum_x = sum_x + x % b product = product * (x % b) x = x // b return sum_x * product def sum_product_cycle(x: int, b: int) -> list[int]: seen = [] while x not in seen: seen.append(x) x = sum_product(x, b) cycle = [] while x not in cycle: cycle.append(x) x = sum_product(x, b) return cycle See also Arithmetic dynamics Dudeney number Factorion Happy number Kaprekar's constant Kaprekar number Meertens number Narcissistic number Perfect digit-to-digit invariant Perfect digital invariant References Arithmetic dynamics Base-dependent integer sequences