TopCoder problem "RepresentableNumbers" used in TCO10 Round 2 (Division I Level Two)



Problem Statement

    Let's call a positive integer A totally odd if each digit in its decimal notation is odd, i.e., one of 1, 3, 5, 7, 9. For example, integers 9, 513, 77777 are totally odd and integers 2 and 99990 are not.



A positive integer N is called representable if it can be represented as N = A + B, where both A and B are totally odd numbers. For example, 2 = 1 + 1 and 4752 = 1377 + 3375 are representable, while 3 and 220 are not.



Given an int X, return the smallest representable number that is greater than or equal to X.
 

Definition

    
Class:RepresentableNumbers
Method:getNext
Parameters:int
Returns:int
Method signature:int getNext(int X)
(be sure your method is public)
    
 

Constraints

-X will be between 1 and 100,000,000, inclusive.
 

Examples

0)
    
1
Returns: 2
1 is not representable, and 2 = 1 + 1 is representable.
1)
    
999
Returns: 1000
999 is not representable, and 1000 = 999 + 1 is representable.
2)
    
2000
Returns: 2000
2000 = 1999 + 1 is representable.
3)
    
4201234
Returns: 4222222
All numbers between 4201234 and 4222221 are not representable, and 4222222 = 3111111 + 1111111 is representable.
4)
    
10101010
Returns: 10102222

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10994

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14280&pm=10994

Writer:

ivan_metelsky

Testers:

PabloGilberto , zhuzeyuan

Problem categories:

Math