eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Vampire Numbers

Vampire Numbers

The number \textbf{1827} is an interesting number, because \textbf{1827=21*87}, and all of the same digits appear on both sides of the '='. The number \textbf{136948} has the same property: \textbf{136948=146*938}. Such numbers are called \textit{Vampire Numbers}. More precisely, a number \textbf{v} is a Vampire Number if it has a pair of factors, \textbf{a} and \textbf{b}, where \textbf{a*b=v}, and together, \textbf{a} and \textbf{b} have exactly the same digits, in exactly the same quantities, as \textbf{v}. None of the numbers \textbf{v}, \textbf{a} or \textbf{b} can have leading zeros. The mathematical definition says that \textbf{v} should have an even number of digits and that \textbf{a} and \textbf{b} should have the same number of digits, but for the purposes of this problem, we'll relax that requirement, and allow \textbf{a} and \textbf{b} to have differing numbers of digits, and \textbf{v} to have any number of digits. Here are some more examples: \textbf{126 = 6 * 21 10251 = 51 * 201 702189 = 9 * 78021 29632 = 32 * 926} Given a number \textbf{X}, find the smallest Vampire Number which is greater than or equal to \textbf{X}. \InputFile There will be several test cases in the input. Each test case will consist of a single line containing a single integer \textbf{X} (\textbf{10} ≤ \textbf{X} ≤ \textbf{1,000,000}). The input will end with a line with a single \textbf{0}. \OutputFile For each test case, output a single integer on its own line, which is the smallest Vampire Number which is greater than or equal to \textbf{X}. Output no extra spaces, and do not separate answers with blank lines.
Лимит времени 1.5 секунда
Лимит использования памяти 32 MiB
Входные данные #1
10
126
127
5000
0
Выходные данные #1
126
126
153
6880
Источник 2011 ACM ICPC Southeast USA Regional Programming Contest