RepresentableNumbers
TCO10 Round 2 · 2010-04-11 · by ivan_metelsky
TCO10 Round 2 · 2010-04-11 · by ivan_metelsky · Math
Problem Statement
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 anint X, return the smallest representable number that is greater than or equal to X.
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
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
Submissions are judged against all 185 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class RepresentableNumbers with a public method int getNext(int X) · 185 test cases · 2 s / 256 MB per case