Camacho numbers are positive integers that are equal to the sum of their digits raised to each power from 1 to the number of digits. For a Camacho number $$n \in \mathbb{N}_0$$ that consists of the digits $$d_1 d_2 \ldots d_m$$, it must therefore hold that \[ \sum_{p=1}^{m} \left( d_1^p + d_2^p + \cdots + d_m^p \right) = n \]

For example, 336 is a Camacho number because \[ (3 + 3 + 6) + (3^2 + 3^2 + 6^2) + (3^3 + 3^3 + 6^3) = 336 \]

Assignment

Example

>>> camacho_term(336, 1)
12
>>> camacho_term(336, 2)
54
>>> camacho_term(336, 3)
270

>>> camacho_sum(336)
336
>>> camacho_sum(4538775)
4538775
>>> camacho_sum(183670618569)
499096875990

>>> iscamacho(336)
True
>>> iscamacho(4538775)
True
>>> iscamacho(183670618569)
False

>>> next_camacho(60)
90
>>> next_camacho(4537541)
4538775
>>> next_camacho(183670618569)
183670618662