#K41027. Single Digit Multiplication Chain

    ID: 26774 Type: Default 1000ms 256MiB

Single Digit Multiplication Chain

Single Digit Multiplication Chain

Given an integer \(N\), repeatedly multiply all of its non-zero digits until you obtain a single-digit number. This process is defined as follows:

Let \(f(N)\) be the product of all non-zero digits of \(N\). Then repeatedly set \(N := f(N)\) until \(N\) is less than 10. Your task is to compute the final single-digit number produced by this process.

Example:

  • For \(N = 39\):
    \(f(39) = 3 \times 9 = 27\);
    \(f(27) = 2 \times 7 = 14\);
    \(f(14) = 1 \times 4 = 4\).
    Hence, the final result is 4.

inputFormat

The input consists of a single integer \(N\) (\(1 \leq N \leq 10^{18}\)), given via standard input.

outputFormat

Output the resulting single-digit number obtained after repeatedly multiplying all non-zero digits of \(N\).

## sample
39
4