F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Vampire Numbers

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 710    Accepted Submission(s): 342


Problem Description
The number 1827 is an interesting number, because 1827=21*87, and all of the same digits appear on both sides of the ¡®=¡¯. The number 136948 has the same property: 136948=146*938.
Such numbers are called Vampire Numbers. More precisely, a number v is a Vampire Number if it has a pair of factors, a and b, where a*b=v, and together, a and b have exactly the same digits, in exactly the same quantities, as v. None of the numbers v, a or b can have leading zeros. The mathematical definition says that v should have an even number of digits and that a and b should have the same number of digits, but for the purposes of this problem, we¡¯ll relax that requirement, and allow a and b to have differing numbers of digits, and v to have any number of digits. Here are some more examples:
126 = 6 * 21
10251 = 51 * 201
702189 = 9 * 78021
29632 = 32 * 926
Given a number X, find the smallest Vampire Number which is greater than or equal to X.
 

Input
There will be several test cases in the input. Each test case will consist of a single line containing a single integer X (10 ¡Ü X ¡Ü 1,000,000). The input will end with a line with a single 0.
 

Output
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 X. Output no extra spaces, and do not separate answers with blank lines.
 

Sample Input
10 126 127 5000 0
 

Sample Output
126 126 153 6880
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 12:50:27, Gzip enabled