Problem:

 

かけざん

太郎君はかけざんを習いたての小学生です。なんとなく、彼はかけざんを気に入っているので、数字を見かけるとかけざんをしたくなります。そんな彼はここのところ、次のような処理を0以上の整数に施すことが好きなようです。

(処理の流れ)

手順1. ある0以上の整数nが10進数表示で一けたならばそこで処理を終了する。そうでなければ手順2に進む

手順2. 10以上の整数nを10進数表示をするとどこかの桁の間に切れ目を入れて二つの数字に分解することが可能である(例えば2012-> 20,12)。このような切り方としてありうるものに対して,得られた二つの数字を掛け合わせて最も大きいものを次のnとして手順1に戻る。(詳しくは下記の"手順2に関する補足を参照")

太郎君はこの処理を気に入っているようですが、何回手順2の操作を繰り返せばよいのか大きい数字だと予想ができず、もしかしたら無限回行われなければならないかもしれないと思っています。そこで、太郎君の兄であり大学生であるあなたに0以上の整数nに対してこの手順2を何回しなければならないかを聞いてきました。

あなたの仕事は、Q個の0以上の整数N1..NQが与えられるので、それぞれの整数で処理の終了までに何回の手順2が施されるかを求めることです。その際にもし無限回の手順が必要ならば、-1を出力してください。

手順2に関する補足

切り分けた結果、桁の初めに0がつくものも考慮に入れる必要があります。

例えばn=1024のとき、1*024 , 10*24 , 102*4をそれぞれ計算するとそれぞれ24,240,408となるため、408が選ばれ、これが次のnとなります。

Input

Q
N1
N2
...
NQ

Qは与えられる0以上の整数の個数を表す

Niは太郎君が気になっている0以上の整数で,i番目のものを表す

Constraints

1≤Q≤100
0≤Ni≤106

Output

Q個の整数を改行区切りで出力せよ

R1
R2
..
RQ

Riは、Niに対して処理を終了するまでに手順2を実行する回数を表す

Niに対して手順2を無限回だけ実行する必要がある場合はRi は -1となる

Sample Input 1

3
9
99
123

Output for the Sample Input 1

0
2
3

9は1桁の数なので、手順2が実行されることはありません。

99は2桁であり、手順2を施せば9,9としか分割できずその次の数は81となる。
81も2桁の数であり、手順2を施せば8,1としか分割できずその次の数は8となる。
1桁の数になったので処理が終了し、答えは2。

123は3桁の数なので、手順2を施します。
この場合は12,3と1,23の二つの分け方があり、それぞれでかけざんをすると36,23となるので、
36が次の数として選ばれます。

Sample Input 2

2
999999
1000000

Output for the Sample Input 2

12 
1



Sample input:
3
9
99
123


Sample output:
0
2
3

Submission status: Wrong Answer

Solution code:
from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n / (10**k)) * (n % (10**k))
                for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)

Submission status: Wrong Answer

Solution code:
#your code goes here
#times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
  #          print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
        #    print(M)
        N=str(M)
        c+=1
    print(N)
    if c>=15:
        d=[int(N)]
        while len(N)>1 and c>=0 and c<50:
            M=0
            for j in range(1,len(N)):
      #          print(N[:j])
                l=int(N[:j])
                r=int(N[j:])
                l*=r
                if M<l:
                    M=l
            print(M)
            k=0
            while k<len(d) and M<d[k]:
                k+=1
            print(d)
            if k>=len(d):
                k=-1
            elif M==d[k]:
                c=-1
            d.insert(k,M)
            N=str(N)
            print(N)
    print(c)

Submission status: Wrong Answer

Solution code:
# your code goes here
#times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
  #          print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
        #    print(M)
        N=str(M)
        c+=1
  #  print(N)
    if c>=15:
        d=[int(N)]
        while len(N)>1 and c>=0 and c<50:
            M=0
            for j in range(1,len(N)):
      #          print(N[:j])
                l=int(N[:j])
                r=int(N[j:])
                l*=r
                if M<l:
                    M=l
    #        print(M)
            k=0
            while k<len(d) and M<d[k]:
                k+=1
       #     print(d)
            if k>=len(d):
                k=-1
            elif M==d[k]:
                c=-1
            d.insert(k,M)
            N=str(N)
      #      print(N)
    print(c)

Submission status: Wrong Answer

Solution code:
Q = int(input())

def solve(x,ans):
    #X = str(x)
    print(x,ans)
    if len(x) == 1:
#        print(ans)
        return
    ret= 0
    for i in range(1,len(x)):
        n = int(x[i:]) * int(x[:i])
        ret = max(ret , n)
        
    #print(ret)
    return solve(str(ret),ans + 1)

for i in range(Q):
    solve(input(),0)

Submission status: Memory Limit Exceeded

Solution code:
for _ in range(int(input())):
    n=int(input())
    a=0;b=[]
    while n//10:
        a+=1
        b+=[n]+b
        x=1;s=m=0
        while n:
            s+=x*(n%10)
            n//=10
            x*=10
            m=max(s*n,m)
        n=m
        if b[-1]==n:print(-1);break
    else:print(a)

Submission status: Accepted

Solution code:
def proc(n):
    new = []
    n = str(n)
    for i in range(1, len(n)):
        new.append(int(n[:i]) * int(n[i:]))
    return max(new)

for _ in range(int(input())):
    ans = 0
    n = int(input())
    while(n > 9):
        n = proc(n)
        ans += 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
Q = sys.stdin.readline()
for _ in range(int(Q)):
    cnt = 0
    N = int(sys.stdin.readline())
    if N != 0:
        digLeng = int(math.log10(N)) + 1
    else:
        digLeng = 1
    while digLeng > 1:
        Nmax = 0
        for dig in range(digLeng):
            lNum = N // int(math.pow(10,dig))
            rNum = N % int(math.pow(10,dig))
            Nmax = max(Nmax,lNum * rNum)
        N = Nmax
        cnt += 1
        if N != 0:
            digLeng = int(math.log10(N)) + 1
        else:
            digLeng = 1
    print(cnt)

Submission status: Accepted

Solution code:
from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)

Submission status: Accepted

Solution code:
q = int(input())
num = [int(input()) for _ in range(q)]
for n in num:
    cnt = 0
    mulnum = [n]
    while True:
        strn = str(n)
        if len(strn) == 1:
            break
        m = 0
        for i in range(len(strn) - 1):
            m = max(m, int(strn[:i+1]) * int(strn[i+1:]))
        if m in mulnum:
            cnt = -1
            break
        else:
            cnt += 1
            mulnum.append(m)
            n = m
    print(cnt)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        q = input()
        for i in range(q):
            n = input()
            tmp = n
            ans = 0
            while tmp >= 10:
                max_val = -1
                s = str(tmp)
                for j in range(len(s)-1):
                    left = int(s[:j+1])
                    right = int(s[j+1:])
                    max_val = max(max_val, left * right)
                tmp = max_val
                ans += 1
            print ans
                    
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Q = int(input())
N = [input() for i in range(0,Q)]

integer = lambda x: int(x) if x != '' else 0
for n in N:
    ans = '0' if int(n) // 10 == 0 else str(n)
    count = 0
    while int(ans) // 10 > 0:
        count += 1
        tmp = 0
        for i in range(1,len(ans)):
            tmp = max(tmp,integer(ans[:i]) * integer(ans[i:]))
        ans = str(tmp)
    else:
        print(count)

Submission status: Accepted

Solution code:
q = int(raw_input())
for i in range(q):
	n = raw_input()
	num = 0
	while 1:
		length = len(n) 
		if length == 1:
			break
		num += 1
		tmp = 0
		for i in range(1,length):
			tmp = max(tmp, int(n[:i])*int(n[i:]))
		n = str(tmp)
	print num

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-

def MaxPro(val):
    mul = 10
    dig = 1
    while val >= mul:
        dig += 1
        mul *= 10
    Max = 0
    for i in range(1, dig):
        tmp = (val%(10**i))*(val/10**i)
        if Max < tmp:
            Max = tmp
    return Max

def ProCnt(val, cnt):
    if val<10:
        return cnt
    else:
        return ProCnt(MaxPro(val), cnt+1)

q = int(raw_input())
for i in range(q):
    n = int(raw_input())
    print ProCnt(n, 0)

Submission status: Accepted

Solution code:
def recur(n, count):
    if n < 10:
        print(count)
        return
    part = []
    i = 10
    while i < n:
        part.append((n%i) * (n/i))
        i *= 10
    recur(max(part), count+1)


q = int(raw_input())
for i in range(q):
    n = int(raw_input())
    lst = []
    recur(n, 0)

Submission status: Accepted

Solution code:
trial = int(input())
for t in range(trial):
    targ = int(input())
    cnt = 0
    while True:
        if targ < 10:
            print(cnt)
            break
        else:
            maxtarg = 0
            for word in range(1,len(str(targ))):
                maxtarg = max( maxtarg , int(str(targ)[0:word]) * int(str(targ)[word:len(str(targ))]))
            targ = maxtarg
            cnt += 1

Submission status: Accepted

Solution code:
import sys

def logic(N):
  counter = 0
  while True:
    if N < 10: break
    maxmult = 0
    i = 1
    while True:
      a = N % (10**i)
      if N == a: break
      b = (N-a) / (10**i)
      maxmult = max(maxmult, a*b)
      i += 1
    N = maxmult
    counter += 1
  print counter

Q = int(raw_input())
for _ in xrange(Q):
  N = int(raw_input())
  logic(N)

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    n=int(input())
    c=0
    while n>9:
        c+=1
        n=max((n//(10**x))*(n%(10**x)) for x in range(1,int(math.log10(n))+1))
    print(c)

Submission status: Accepted

Solution code:
# your code goes here
#times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
    #        print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
      #      print(M)
        N=str(M)
        c+=1
  #  print(N)
    if c>=15:
        d=[int(N)]
        while len(N)>1 and c>=0 and c<50:
            M=0
        #    print(d)
            for j in range(1,len(N)):
        #        print(N[:j])
                l=int(N[:j])
                r=int(N[j:])
                l*=r
                if M<l:
                    M=l
      #          print(M)
            k=0
            while k<len(d) and M>d[k]:
                k+=1
         #   print(k)
            if k>=len(d):
                k=-1
            elif M==d[k]:
                c=-1
            d.insert(k,M)
            N=str(M)
            c+=1
        #    print(k)
    print(c)

Submission status: Accepted

Solution code:
Q = int(input())
src = [int(input()) for i in range(Q)]
for n in src:
    ans = 0
    _n = n
    st = set()
    while _n >= 10:
        if _n in st:
            print(-1)
            break
        st.add(_n)
        s = str(_n)
        next = 0
        for i in range(1,len(s)):
            next = max(next, int(s[:i]) * int(s[i:]))
        _n = next
        ans += 1
    else:
        print(ans)

Submission status: Accepted

Solution code:
q = int(input())
for i in range(q):
    n = int(input())
    
    cnt = 0
    li = list()
    while n >= 10:
        cnt += 1
        di = 10
        ma = 0
        while di < n:
            l = n % di
            u = n // di
            ma = max(ma, l * u)
            di *= 10
        n = ma
        if ma in li:
            cnt = -1
            break
        li.append(ma)
    print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    q = I()
    qi = 0

    while qi < q:
        qi += 1
        n = S()
        r = 0
        while len(n) > 1:
            r += 1
            t = 0
            for i in range(1,len(n)):
                u = int(n[:i]) * int(n[i:])
                if t < u:
                    t = u
            n = str(t)
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
Q = int(input())

def solve(x,ans):
    #X = str(x)
#    print(x,ans)
    if len(x) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(x)):
        n = int(x[i:]) * int(x[:i])
        ret = max(ret , n)
        
    #print(ret)
    return solve(str(ret),ans + 1)

for i in range(Q):
    solve(input(),0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
Q = input()

for loop in range(Q):
	n = str(input())
	cnt = 0
	while len(n) > 1:
		cnt += 1
		nmin = 0
		for i in range(len(n) - 1):
			n1 = int(n[:i + 1])
			n2 = int(n[i + 1:])
			nmin = max(nmin, n1 * n2)
		n = str(nmin)
	print(cnt)

Submission status: Accepted

Solution code:
from functools import reduce

g=lambda x,y:x*y
cv=lambda s:str(max([reduce(g,list(map(int,[s[:i],s[i:]]))) for i in range(1,len(s))]))

for _ in range(int(input())):
	c=0
	n=input()
	s=set()
	while 1:
		if len(n)==1:break
		if n in s:
			c=-1
			break
		s.add(n)
		n=cv(n)
		c+=1
	print(c)

Submission status: Accepted

Solution code:
for i in range(input()):
	n = raw_input()
	c = 0
	while len(n) > 1:
		c += 1
		maxn = 0
		for i in range(1,len(n)):
			a = int(n[:i])
			b = int(n[i:])
			maxn = max(maxn,a*b)
		n = str(maxn)
	print c

Submission status: Accepted

Solution code:
for i in range(input()):
	n = raw_input()
	c = 0
	while len(n) > 1:
		c += 1
		maxn = 0
		for i in range(1,len(n)):
			maxn = max(maxn, int(n[:i])*int(n[i:]))
		n = str(maxn)
	print c

Submission status: Accepted

Solution code:
for i in range(input()):
	n = raw_input()
	c = 0
	while len(n) > 1:
		c += 1
		maxn = 0
		for i in range(1,len(n)):
			maxn = max(maxn, int(n[:i])*int(n[i:]))
		n = str(maxn)
	print c

Submission status: Accepted

Solution code:
import sys
# -*- coding: utf-8 -*-

def multiple(target,count):
    length = len(target)
    result = []
    if length == 1:
        return count
    for i in range(1,length):
        prefix = int(target[:i])
        suffix = int(target[i:])
        result.append(prefix*suffix)
    return multiple(str(max(result)), count+1)

count=int(input())
for i in range(count):
    print(multiple(input(),0))

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    q = int(input())
    power10 = [1]
    for i in range(7):
        power10.append(10*power10[-1])

    for _ in range(q):
        N = int(input())
        if N//10 == 0:
            print(0)
            continue

        visited = {N}
        cnt = 0
        while True:
            cnt += 1
            next_number = -1
            for i in range(1,len(str(N))):
                next_number = max(next_number,(N//power10[i])*(N%power10[i]))
            if next_number in visited:
                cnt = -1
                break
            if next_number//10 == 0:
                break
            else:
                visited.add(next_number)
                N = next_number

        print(cnt)        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    f = [0]*10
    M = 1000000
    for n in range(10,M+1):
        k = str(n)
        m = 1
        for i in range(1,len(k)):
            nm = int(k[:i])*int(k[i:])
            if m < nm:
                m = nm
        f.append(f[m]+1)
    q = I()
    for i in range(q):
        print(f[I()])
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def solve(n):
    ans = 0
    mp = {}
    while (n >= 10):
        s = str(n)
        next = -1
        for i in range(1, len(s)):
            next = max(next, int(s[0:i])*int(s[i:]))
        if next in mp:
            ans = -1
            break
        mp[next] = True
        n = next
        ans += 1
    return ans


def main():
    q = int(input())
    for i in range(q):
        n = int(input())
        print(solve(n))


main()

Submission status: Accepted

Solution code:
def calc(n):
    if n>=10 and n<100:
        return (n//10)*(n%10)
    elif n>=100 and n<1000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        return max(r1,r2)
    elif n>=1000 and n<10000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        return max(r1,r2,r3)
    elif n>=10000 and n<100000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        return max(r1,r2,r3,r4)
    elif n>=100000 and n<1000000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        return max(r1,r2,r3,r4,r5)
    else:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        r6=(n//1000000)*(n%1000000)
        return max(r1,r2,r3,r4,r5,r6)
n=int(input())


for i in range(n):
    cnt=0
    a=int(input())
    while a>=10:
        a=calc(a)
        cnt+=1

    print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    while 1:
        n = II()
        ans = 0
        if n == 0:
            break
        i = 1
        while i < n / 2:
            tmp = 0
            l = i
            while tmp < n:
                tmp += l
                l += 1
            if tmp == n:
                ans += 1
            i += 1
        print(ans)  

    return

#B
def B():

    def f(x):
        tmp = 0
        for i in range(len(x)-1):
            x1 = int(x[:i+1])
            x2 = int(x[i+1:])
            tmp = max(tmp, x1 * x2)
        return tmp

    q = II()
    for i in range(q):
        ans = 0
        n = II()
        while n > 9:
            ans += 1
            n = f(str(n))

        print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    R, C, K = LI()
    n = II()
    rc = LIR_(n)
    fldr = [0 for _ in range(R)]
    fldc = [0 for _ in range(C)]
    for r, c in rc:
        fldr[r] += 1
        fldc[c] += 1
    fldcs = fldc[::1]
    fldcs.sort()
    fldrs = fldr[::1]
    fldrs.sort()
    ans = 0
    dr = defaultdict(int)
    dc = defaultdict(int)
    for k in range(R):
        dr[fldr[k]] += 1
    for k in range(C):
        dc[fldc[k]] += 1
    for k in range(K+1):
        ans += dr[K - k] * dc[k]
    for r, c in rc:
        a = fldr[r] + fldc[c]
        if a == K:
            ans -= 1
        elif a == K + 1:
            ans += 1
    print(ans)
    return

#F
def F():
    n, m = LI()
    uvl = LIR_(m)
    dist = [[inf] * n for _ in range(n)]
    dist0 = defaultdict(int)
    full = []
    d = 0
    for u, v, l in uvl:
        if u == 0:
            dist0[v] = l + 1
            full.append(v)
            d += 1
        elif v == 0:
            dist0[u] = l + 1
            d += 1
            full.append(u)
        else:
            l += 1
            dist[u][v] = l
            dist[v][u] = l
    for i in range(n):
        dist[i][i] = 0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    fulls = itertools.combinations(range(d), 2)
    ans = inf
    for a, b in fulls:
        a, b = full[a], full[b]
        tmp = dist0[a] + dist0[b] + dist[a][b]
        ans = min(ans, tmp)
    print(-1 if ans == inf else ans)
    return

#G
def G():
    s = S()
    s = s[::-1]
    M_count = s.count("M")
    M_lis = [0] * M_count
    M_count //= 2
    tmp = 0
    k = 0
    for i in range(len(s)):
        if s[i] == "+":
            tmp += 1
        elif s[i] == "-":
            tmp -= 1
        else:
            M_lis[k] = tmp
            k += 1
    M_lis.sort()
    print(-sum(M_lis[:M_count]) + sum(M_lis[M_count:]))


    return

#H
def H():
    def f(t):
        return a * t + b * math.sin(c * t * math.pi)
    a, b, c = LI()
    ok = 99 // a + 1
    ng = 0
    while 1:
        t = (ok + ng) / 2
        ft = f(t)
        if abs(ft - 100) <= 10 ** (-6):
            print(t)
            return
        if ft > 100:
            ok = t
        if ft < 100:
            ng = t
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    n=int(input())
    c=0
    while n>9:
        c+=1
        n=max((n//(10**x))*(n%(10**x)) for x in range(1,int(math.log10(n))+1))
    print(c)

Submission status: Accepted

Solution code:
"かけざん"
"最大のものを取得して、一桁になるまでに操作を行う回数を答える"


def kakezan(n):
    ret = 0
    str_n = str(n)
    digit_amount = len(str_n)
    for i in range(digit_amount-1):
        # print(str_n[:i+1])
        # print(str_n[i+1:])
        # print("")
        ret = max(ret, int(str_n[:i+1])*int(str_n[i+1:]))

    return ret


Q = int(input())  # 入力される整数の個数
N = [int(input()) for i in range(Q)]

for n in N:
    cnt = 0
    while n >= 10:
        n = kakezan((n))
        cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

def main():
    Q = int(input())
    for _ in range(Q):
        n = input()
        count = 0
        while len(n) > 1:
            if count == 1000000:
                count = -1
                break
            tmp = 0
            for i in range(1,len(n)):
                tmp = max(tmp, int(n[:i])*int(n[i:]))
            count += 1
            n = str(tmp)
        print(count) 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(N, cnt):
    if len(str(N)) == 1:
        return cnt
    sN = str(N)
    maxNum = 0
    for i in range(1, len(sN)):
        left = int(sN[0:i])
        right = int(sN[i:])
        maxNum = max(left * right, maxNum)
    ret = solve(maxNum, cnt + 1)
    return ret


Q = int(input())
for i in range(Q):
    N = int(input())
    ans = solve(N, 0)
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
q = int(input())
for _ in range(q):
    n = input()
    for k in range(len(n)**2):
        if len(n) == 1:
            print(k)
            break
        n = str(max(int(n[:i]) * int(n[i:]) for i in range(1, len(n))))

Submission status: Accepted

Solution code:
def split(x):
    assert(isinstance(x, int))
    sx = str(x)
    l = len(sx)
    candidates = []
    for idx in range(1, l):
        first = sx[idx:]
        candidates.append(int(sx[:idx]) * int(sx[idx:]))
    if len(candidates) == 0:
        return None
    else:
        return max(candidates)


def problem1():
    Q = input()
    answers = []
    for _ in range(int(Q)):
        N = int(input())
        x = N
        cnt = 0
        while True:
            next_x = split(x)
            if next_x is None:
                break
            elif x == next_x:
                cnt = -1
                break
            else:
                cnt += 1
            x = next_x
        answers.append(str(cnt))
    print('\n'.join(answers))


if __name__ == '__main__':
    problem1()

Submission status: Accepted

Solution code:
def solve(s):
    return max(int(s[:i]) * int(s[i:]) for i in range(1, len(s)))

for _ in range(int(input())):
    s = input()
    cnt = 0
    while len(s) > 1:
        cnt += 1
        s = str(solve(s))
    print(cnt)

Submission status: Accepted

Solution code:
Q = int(input())
for i in range(Q):
    n = int(input())
    ans = 0
    while n >= 10:
        s = str(n)
        a = 0
        for i in range(len(s) - 1):
            a = max(a, int(s[:i + 1]) * int(s[i + 1:]))
        n = a
        ans += 1
    print(ans)

Submission status: Accepted

Solution code:
def solve(dic, cnt, n):
  if n < 10:
    return cnt

  if n in dic:
    return -1

  dic[n] = True

  s = str(n)
  max_score = 0
  for i in range(1, len(s)):
    a, b = int(s[:i]), int(s[i:])
    max_score = max(max_score, a * b)

  return solve(dic, cnt + 1, max_score)

q = int(input())
for _ in range(q):
  dic = dict()
  print(solve(dic, 0, int(input())))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)

using namespace std;
typedef long long int ll;

int main(void){
	ll Q;
	cin>>Q;
	while(Q--){
		string str;
		int cnt = 0;
		cin>>str;
		vector<int> n(str.size());
		rep(i,str.size())n[i]=str[i]-'0';
		while(n.size()>1){
			double num=0;
			if(n[0]<=n[n.size()]){
				loop(i,1,n.size())num=num*10+(n[i]);
				num = num * (n[0]);
			}else{
				rep(i,n.size()-1){
					num=num*10+n[i];		
				}num = num * (n[n.size()-1]);
			}
			int size=1;
			rep(i,n.size()-1)size*=10;
			n.clear();
			if((int)num/size==0)size/=10;
			while(num!=0){
				int no=(int)num/size;
				num=(int)num%size;
				size=size/10;
				n.push_back(no);
			}
			cnt++;
		}
		cout<<cnt<<endl;
	}
}

Submission status: Runtime Error

Solution code:
import sys
import math
Q = sys.stdin.readline()
for _ in range(int(Q)):
    cnt = 0
    N = int(sys.stdin.readline())
    digLeng = int(math.log10(N)) + 1
    while digLeng > 1:
        Nmax = 0
        for dig in range(digLeng):
            lNum = N // int(math.pow(10,dig))
            rNum = N % int(math.pow(10,dig))
            Nmax = max(Nmax,lNum * rNum)
        N = Nmax
        cnt += 1
        if N != 0:
            digLeng = int(math.log10(N)) + 1
        else:
            digLeng = 1
    print(cnt)

Submission status: Runtime Error

Solution code:
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k))
                for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)

Submission status: Runtime Error

Solution code:
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        L = [(n // (10**k)) * (n % (10**k))
             for k in range(1, int(log10(n)) + 1)]
        n = max(L)
        j += 1
    print(j)

Submission status: Runtime Error

Solution code:
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        m_max = 0
        for k in range(1, int(log10(n)) + 1):
            m = (n // (10**k)) * (n % (10**k))
            if m >= m_max:
                m_max = m
        n = m_max
        j += 1
    print(j)

Submission status: Runtime Error

Solution code:
#times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
  #          print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
        #    print(M)
        N=str(M)
        c+=1
    if c>=15:
        d=[int(N)]
        while c>=0 and c<50:
            while len(N)>1 and c<50:
                M=0
                for j in range(1,len(N)):
  #          print(N[:j])
                    l=int(N[:j])
                    r=int(N[j:])
                    l*=r
                    if M<l:
                        M=l
        #    print(M)
                k=0
                while k<len(d) and M<d[k]:
                    k+=1
                if M==d[k]:
                    c=-1
                else:
                    d.insert(j,M)
                N=str(N)
    print(c)

Submission status: Runtime Error

Solution code:
Q = int(input())

def solve(x,ans):
    X = str(x)
    if len(X) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(X)):
        n = int(X[i:]) * int(X[:i])
        ret = max(ans,n)
        
    #print(ret)
    return solve(ret,ans + 1)

for i in range(Q):
    solve(int(input()),0)