Problem Statement
For a nonnegative integer x, we define S(x) := (the product of all digits in the decimal representation of x without extra leading zeros). For example, S(4) = 4, S(114514) = 1 * 1 * 4 * 5 * 1 * 4 = 80, S(810) = 8 * 1 * 0 = 0.
Given an integer x, you are going to replace x with S(x) repeatedly until x becomes one-digit integer (including 0).
For example, let's assume that you are given x = 893. First, since S(893) = 8 * 9 * 3 = 216, you replace x with 216. Then, since S(216) = 2 * 1 * 6 = 12, you replace x with 12. And since S(12) = 1 * 2 = 2, you replace x with 2, and the process ends.
Given the integer x you'll process, return the one-digit integer you finally made.
Given an integer x, you are going to replace x with S(x) repeatedly until x becomes one-digit integer (including 0).
For example, let's assume that you are given x = 893. First, since S(893) = 8 * 9 * 3 = 216, you replace x with 216. Then, since S(216) = 2 * 1 * 6 = 12, you replace x with 12. And since S(12) = 1 * 2 = 2, you replace x with 2, and the process ends.
Given the integer x you'll process, return the one-digit integer you finally made.
Definition
- Class:
- DigitMultiple
- Method:
- calc
- Parameters:
- int
- Returns:
- int
- Method signature:
- int calc(int x)
- (be sure your method is public)
Constraints
- x will be between 1 and 1,000,000, inclusive.
Examples
6
Returns: 6
x is already a one-digit integer, so the answer is the given x itself.893
Returns: 2
Described in the problem statement.114514
Returns: 0
Note that in some cases the answer may be 0.1919
Returns: 8