Number Theory for Newbies

Given any positive integer, if we permute its digits, the difference between the number we get and the given number will always be divisible by 9. For example, if the given number is 123, we may rearrange the digits to get 321. The difference = 321 - 123 = 198, which is a multiple of 9 (198 = 9 × 22). We can prove this fact fairly easily, but since we are not having a maths contest, we instead try to illustrate this fact with the help of a computer program. Input Each line of input gives a positive integer n (≤ 2000000000). You are to find two integers a and b formed by rearranging the digits of n, such that a − b is maximum. a and b should NOT have leading zeros. Output You should then show that a − b is a multiple of 9, by expressing it as ‘9 * k’, where k is an integer. See the sample output for the correct output format. Sample Input 123 2468 Sample Output 321 - 123 = 198 = 9 * 22 8642 - 2468 = 6174 = 9 * 686