A positive integer is called special if all of its digits are nonzero and any two adjacent digits are consecutive (not necessarily in ascending order).
a) Find the largest special number for which the sum of its digits is .
b) Find the smallest special number for which the sum of its digits is .
Solution
a) The largest number will have as many digits as possible, so we will choose the smallest possible digits. As next to a we can only put a , and , we choose , with digits equal to and digits equal to .
b) As and , if in the decimal writing of we would use at most digits, the sum of these digits would be at most , false. Therefore we can't use fewer than digits. To use exactly digits, we must have groups of and , and another two digits whose sum is . The two digits could be and , or and . In both cases, the number of even digits of differs by from the number of its odd digits. This is impossible, because in the decimal writing of a special number, the even digits alternate with the odd ones, so the number of its even digits is either equal to that of its odd digits, or differs from it by . Therefore must have at least digits. We are looking for three consecutive digits, smaller than , whose sum is at least and which are the first three digits of . Moreover, we are looking for the first digit of to be as small as possible. The smallest digits that fulfill these requirements are , , . The solution is .