Given a non-negative integer n, repeatedly multiply together all of its digits to form a new number, and repeat this process until the result is a single digit (0-9). Count how many such multiplication rounds are needed; this count is the multiplicative persistence of n.
For example, 39 -> 39=27 -> 27=14 -> 1*4=4 (3 rounds). If n is already a single digit, the persistence is 0.
Line 1: n given as a string of decimal digits (no leading zeros unless n is exactly 0), with at most 20 digits.
A single integer: the multiplicative persistence of n.
n has between 1 and 20 digitsn contains only characters 0-9, with no leading zero unless n is exactly 0Example 1
Input
39
Expected
3
Explanation
39 -> 3*9=27 -> 2*7=14 -> 1*4=4, which is a single digit after 3 rounds.
Example 2
Input
7
Expected
0
Explanation
7 is already a single digit, so the persistence is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →