Crazy numbers

Given three natural numbers b, d and n, let us say that a natural number
x is crazy if x is a multiple of n, and x represented in base b

- has exactly d digits (maybe with a leading zero),

- and does not have two equal consecutive digits.

Given b, d and n, can you find all crazy numbers?

Input

Input consists of several cases, each one with b, d and n. You can
assume 3 ≤ b ≤ 10, d ≥ 1, and n < b^(d) ≤ 10¹⁷.

Output

For every case, print in order and with exactly d digits all crazy
numbers in base b, followed by a line with ten dashes. All given cases
are such that there are between 1 and 100 crazy numbers.

Observation

The expected solution requires less than 0.1 seconds to solve Sample
input 2.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:35:02.904Z

© Jutge.org, 2006–2026.
https://jutge.org
