#K15731. Distinct Powers Sum Representation

    ID: 24422 Type: Default 1000ms 256MiB

Distinct Powers Sum Representation

Distinct Powers Sum Representation

Given two integers n and x, determine whether n can be expressed as the sum of one or more distinct powers of x. In other words, decide if there exists a selection of distinct non‐negative integers i such that

[ n = x^{i_1} + x^{i_2} + \cdots + x^{i_k} ]

for some k ≥ 1. If such a representation exists, output Yes; otherwise, output No.

The powers considered are x0, x1, x2, \dots</sup> and so on, up to the point where the power exceeds n.

inputFormat

The input consists of a single line containing two space-separated integers n and x.

outputFormat

Output a single line containing either Yes if n can be expressed as the sum of one or more distinct powers of x, or No otherwise.## sample

10 2
Yes