#B3866. The 495 Transformation
The 495 Transformation
The 495 Transformation
Given a three-digit number with all distinct digits, perform the following procedure:
- Rearrange its digits to form the largest number possible and the smallest number possible (treating the number as three digits, possibly with leading zeros).
- Subtract the smallest from the largest to obtain a new number.
- Repeat the process with the new number.
It is proven that this process will always reach \(495\). For example, starting from \(352\):
- Arrange: \(532\) and \(235\); \(532 - 235 = 297\).
- Then: \(972 - 279 = 693\).
- Then: \(963 - 369 = 594\).
- Finally: \(954 - 459 = 495\).
Your task is to determine the number of transformations required to reach \(495\) for a given initial number.
inputFormat
The input consists of a single three-digit integer with distinct digits.
outputFormat
Output the number of transformations required for the given number to become \(495\).
sample
352
4