Problems > Multiplicative Persistence

Multiplicative Persistence

Difficulty: 1100 2000 ms 128 MB

math implementation

Repeatedly replace N with the product of its digits until a single digit remains. Print how many replacements were made.

Input: one integer N.

Output: the multiplicative persistence of N.

Constraints:

  • 0 ≤ N ≤ 1018

Sample Tests

Input 1
39
Output 1
3
Input 2
4
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.