#P2699. Powers in Range

    ID: 15964 Type: Default 1000ms 256MiB

Powers in Range

Powers in Range

Little Hao is troubled by exponentiation. He has encountered a problem where he needs to find all powers of a given number that lie within a specified range. Formally, given three integers: the base w and two limits l and r, find all values of \(w^i\) such that \(l \le w^i \le r\) for non-negative integers \(i\). In the special case when \(w=1\), note that \(1^i=1\) for all \(i\); therefore, if \(1\) lies in the interval \([l, r]\), output \(1\) exactly once, otherwise output \(-1\).

If there are no such numbers, output \(-1\). Otherwise, output the numbers in increasing order, separated by a single space.

inputFormat

The input consists of a single line containing three space-separated integers: w, l, and r, representing the base, the lower bound and the upper bound respectively.

outputFormat

If there exists at least one power \(w^i\) within the range \([l, r]\), output all such numbers in increasing order separated by a space. Otherwise, output \(-1\).

sample

3 1 10
1 3 9