Problem:


階乗 II

n! = n &times; (n &minus; 1) &times; (n &minus; 2) &times; ...  &times; 3 &times; 2 &times; 1

を n の階乗といいます。例えば、12 の階乗は

12! = 12 &times; 11 &times; 10 &times; 9 &times; 8 &times; 7 &times; 6 &times; 5 &times; 4 &times; 3 &times; 2 &times; 1 = 479001600

となり、末尾に 0 が 2 つ連続して並んでいます。

整数 n を入力して、n! の末尾に連続して並んでいる 0 の数を出力するプログラムを作成してください。ただし、n は 20000 以下の正の整数とします。

Input

複数のデータが与えられます。各データに n (n ≤ 20000) が１行に与えられます。n が 0 の時入力の最後とします。

データの数は 20 を超えません。

Output

各データに対して n! の末尾に連続して並んでいる 0 の数を１行に出力して下さい。

Sample Input

2
12
10000
0

Output for the Sample Input

0
2
2499



Sample input:
2
12
10000
0


Sample output:
0
2
2499

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())
    if n == 0:
        break
    a=math.factorial(n)
    s=0
    while True:
        if a%10 == 0:
            s += 1
            a = a//10
        else:
            break
            
    print(s)

Submission status: Accepted

Solution code:
pow5 = [1, 5, 25, 125, 625, 3125, 15625, 78125]

while True:
	n = int(input())
	if n == 0: break
	ans, i = 0, 1
	while n >= pow5[i]:
		ans += n // pow5[i]
		i += 1
	print(ans)

Submission status: Accepted

Solution code:
import math
while 1:
    try:
        count=0
        N=int(input())
        if N==0:break
        n=str(math.factorial(N))
        for i in n[::-1]:
            if i=="0":count +=1
            else:
                print(count)
                break
    except:break

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    ans = 0
    if n == 0:
        break
    while  True:
        n //= 5
        ans += n
        if n == 0:
            break
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    x=0
    while n>0:
        a=n//5
        x+=a
        n=n//5
    print(x)

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    if n == 0 :
        break
    
    S = 1
    for i in range(n) :
        S *= (i+1)
    
    ans = 0
    while True :
        if S % 10 != 0 :
            break
        else :
            S = S // 10
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import math
while True:
    n = int(input())
    if n == 0:
        break
    i = 0
    n = str(math.factorial(n))[::-1]
    while n[i] == '0':
        i += 1
    print(i)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break

    x = 0
    while n > 0:
        x += n // 5
        n = n // 5
    print(x)

Submission status: Accepted

Solution code:
while True:
    five_num = 0
    expo = 1
    x = int(input())
    if x == 0:
        break
    elif x < 10:
        print(0)
    else:
        while x >= 5 ** expo:
            five_num += int((x/(5 ** expo)))
            expo += 1
        print(five_num)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    
    a = 1
    for i in range(1,n+1):
        a *= i
    
    count = 0
    while(a % 10 == 0):
        count += 1
        a //= 10
    
    print(count)

Submission status: Accepted

Solution code:
import math


A = 1
while True:
    n = int(input())
    if n == 0:
        break
    A = math.factorial(n)
    
    m = 0    
    while True:
        if A % 5 != 0:
            break
        else:
            A = A // 5
            m = m + 1
            
    print(m)

Submission status: Accepted

Solution code:
import math
N = 1
while True:
    n = int(input())
    if n == 0:
        break
    N = math.factorial(n)
    
    c = 0    
    while True:
        if N % 10 != 0:
            break
        else:
            N = N // 10
            c = c + 1
            
    print(c)

Submission status: Accepted

Solution code:
def f(n):
    for i in range (1,n):
        n*=i
    return n
        
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=str(f(n))
        s=0
        l=len(a)
        for i in range(l-1,-1,-1):
            if a[i]=='0':
                s+=1
            else:
                break
        print(s)

Submission status: Accepted

Solution code:
while True:
    num = int(input())

    if num == 0:
        break

    a = 5
    c = 0
    while num >= a:
        c = c + (num // a)
        a = a*5

    print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    s=1
    for i in range(n):
        s*=(i+1)
    t=0
    while s%10==0:
        t+=1
        s//=10
    print(t)

Submission status: Accepted

Solution code:
a=[]

A=0
B=0
C=0
while True:
    N=int(input())
    if N==0:
        break
    else:
        for i in range (N+1):
            if i%2 != 0:
                pass
            else:
                while i!=0 and i%2==0 :
                    i=i//2
                    A+=1
        for i in range (N+1):
            if i%5 != 0:
                pass
            else:
                while i!=0 and i%5==0 :
                    i=i//5
                    B+=1        
    
        for i in range (N+1):
            if i%10 != 0:
                pass
            else:
                while i!=0 and i%10==0 :
                    i=i//10
                    C+=1
        D=A-C
        E=B-C
        if D<E:
            print(D+C)
        else:
            print(E+C)
        A=0
        B=0
        C=0

Submission status: Accepted

Solution code:
while True:
    p=int(input())
    if p==0:
        break
    else:
        i=1
        q=0
        while True:
            if 5*i>p:
                break
            else:
               q+=p//5**i
            i+=1
        print(q)

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())

    if n==0:
        break
    b=n//5
    c=n//(5**2)
    d=n//(5**3)
    e=n//(5**4)
    f=n//(5**5)
    g=n//(5**6)
    print(b+c+d+e+f+g)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    a=n//5
    b=n//25
    c=n//125
    d=n//625
    e=n//3125
    f=n//15625    
    print(a+b+c+d+e+f)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    x=1
    for i in range(2,n+1):
        x*=i
    a=0
    while x%10==0:
        a+=1
        x=x//10
    print(a)

Submission status: Accepted

Solution code:
import math
while 1:
    n=int(input())
    i=0
    if n==0:
        break
    n=str(math.factorial(n))[::-1]
    while n[i]=='0':
        i+=1
    print(i)

Submission status: Accepted

Solution code:
def count(n):
    a=0
    while n and not n%5:
        a+=1
        n//=5
    return a

while True:
    n=int(input())
    if n==0:
        break
    
    ans=0
    for i in range(n+1):
        ans+=count(i)
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    
    s=1
    for i in range(1,n+1,1):
        s*=i
        i+=1
        
    v=0
    while True:
        if s%10==0:
            s=s//10
            v+=1
        else:
            break
    print(v)

Submission status: Accepted

Solution code:
while True:
    n=5
    a=int(input())
    if a==0:
        break
    elif a>=5:
        sum=0
        while n<=a:
            t=a//n
            sum+=t
            n*=5
        print(sum)
        
    else:
        print(0)

Submission status: Accepted

Solution code:
while True:
  a = int(input())
  if a == 0:
    break
  n = int(1)
  c = int(0)
  while True:
    if a//(5**n) == 0:
      break
    else:
      n += 1
  #print(n)
  for b in range(n):
    c += (a//(5**(b+1)))
  print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n == 0:
        break
    x=0
    y=1
    while True:
        b=n//(5**y)
        if  b == 0:
            break
        x=x+b
        y += 1
    print(x)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    else:
        m = 1
        a=0
        for i in range(1,n+1):
            m *= i
        while m%10 == 0:
            m = m//10
            a += 1
        print(a)

Submission status: Accepted

Solution code:
import math
while True:
    n = int(input())
    if n == 0:
        break

    x = 0
    while True:
        n = n // 5
        x += n
        if n == 0:
            break

    print(x)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    count=0
    for i in range(n-1):
        n=n*(i+1)
    while n%10==0:
        n=n//10
        count+=1
        if n%10>0:
            break
    print(count)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    s=1
    if n==0:
        break
    else:
        for i in range(n):
            s*=(i+1)
    
    t=0
    while True:
        if s%10!=0:
            break
        else:
            s=s//10
            t+=1
    print(t)

Submission status: Accepted

Solution code:
n=int(input())
while n!=0:
    print( (n//5) + (n//(5**2)) + (n//(5**3)) + (n//(5**4)) + (n//(5**5)) + (n//(5**6)) )
    n=int(input())

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n > 0:
        a = n // 5
        b = n // (5**2)
        c = n // (5**3)
        d = n // (5**4)
        e = n // (5**5)
        f = n // (5**6)
        print(a+b+c+d+e+f)
        
    if n == 0:
        break

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    a=1
    for i in range(1,n+1):
        a*=i
    b=0
    while a%10==0:
       a=a//10
       b+=1
    print(b)

Submission status: Accepted

Solution code:
n=int(input())
while n!=0:
    N=1
    for i in range(1,n+1):
        N=N*i
    t=0
    while N%10==0:
        t+=1
        N=N//10
    print(t)
    n=int(input())

Submission status: Accepted

Solution code:
#(39)ICP得点集計ソフトウェア
while True:
     n=int(input())
     if n==0:
          break
     count=0
     for i in range(n-1):
          n=n*(i+1)
     while n%10==0:
          n=n//10
          count+=1
          if n%10>0:
               break
     print(count)

Submission status: Accepted

Solution code:
import re
import math

while True:
    n = int(input())
    if n==0:
        break
    x = math.factorial(n)
    if x%10==0:
        y = str(x)
        z = re.search('[0]+$',y)
        a = z.start()
        b = z.end()
        print(b-a)
    else:
        print(0)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    x=1
    y=[]
    z=0
    if n==0:
        break
    for i in range(1,n+1):
        x*=i
    for j in str(x):
        y+=[j]
    y.reverse()
    for k in y:
        if k=='0':
            z+=1
        elif k!=0:
            break
    print(z)

Submission status: Accepted

Solution code:
def F(n):
    p=0
    while n and not n % 5 :
        p+=1
        n//=5
    return p
while True:
    n=int(input())
    if not n:
        break
    r=0
    for i in range(n+1):
        r+=F(i)
    print(r)

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())
    s=math.factorial(n)
    t=0
    if n==0:break
    for i in range(n):
        if s%10==0:
             s+=s//10
             t+=1
        else:break
    print(t)

Submission status: Accepted

Solution code:
while True:
  n=int(input())
  if n == 0:
    break
  ans=0
  while n >4:
    ans += n//5
    n = n//5
  print(ans)

Submission status: Accepted

Solution code:
while True :
    n=int(input())
    if n==0 :
        break
    sum=1
    ans=0
    for i in range(1,n+1):
        sum=sum*i
        while True:
            if sum%10==0:
                ans+=1
                sum=sum//10
            else:break
       
    print(ans)

Submission status: Accepted

Solution code:
def f(n):
    for i in range(1,n):
        n*=i
    return n
        
        
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=str(f(n))
        s=0
        l=len(a)
        for i in range(l-1,-1,-1):
            if a[i]=="0":
                s+=1
            else:
                break
        print(s)

Submission status: Accepted

Solution code:
import math
v=0
while True:
    n=int(input())
    if n==0:
        break
    s=0
    for i in range(1,7):
        s+=n//(5**i)
    print(s)

Submission status: Accepted

Solution code:
for i in range(20):
    a=int(input())
    if a==0: break
    zer=a//5+a//(5**2)+a//(5**3)+a//(5**4)+a//(5**5)+a//(5**6)
    print(zer)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    v=1
    for i in range (0,n):
        v*=(n-i)
    s=0
    while True:
        if v%10!=0:
            break
        else:
            s+=1
            v//=10
    print(s)

Submission status: Accepted

Solution code:
while True:
    a=int(input())
    if a==0:
        break
    b=1
    for i in range(1,a+1):
       b=b*i
    j=0
    while True:
        if b%10 != 0:
            break
        b=b//10
        j=j+1
    print(j)

Submission status: Accepted

Solution code:
import math
while 1:
    n,i=int(input()),0
    if n==0:break
    n=str(math.factorial(n))[::-1]
    while n[i]=='0':i+=1
    print(i)

Submission status: Accepted

Solution code:
import math
while True:
    T = 0
    n = int(input())
    N = math.factorial(n)
    if n == 0:
        break
    while True:
        if N % 10 == 0:
            N = N//10
            T += 1
        else:
            break
    print(T)

Submission status: Accepted

Solution code:
import math
a=int(input())
while a!=0:
    c=0
    b=math.factorial(a)
    a=int(input())
    while b%10==0:
        b=b//10
        c=c+1
    print(c)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n ==0:
        break
    x = 1
    for i in range(1, n+1):
        x *= i
    y = 0
    while True:
        if x % 10 != 0:
            break
        x = x // 10
        y +=1
    print(y)

Submission status: Accepted

Solution code:
import math
while True:
    b=0
    n=int(input())
    if n==0:
        break
    a=math.factorial(n)
    while True:
        if a%10==0:
            b+=1
            a=a//10
        else:
            break
    print(b)

Submission status: Accepted

Solution code:
import math
while True:
    b=0
    a=int(input())
    if a==0:
        break
    A=math. factorial(a)
    while True:
        if A%10==0:
           b=b+1
           A=A//10
        else:
            break
    print(b)

Submission status: Accepted

Solution code:
import math
while True:
    i=0
    n=int(input())
    a=math.factorial(n)
    if n==0:
        break
    while True:
        if a%10==0:
            a=a//10
            i+=1
        else:
            break
    print(i)

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())
    if n==0:
        break
    a=math.factorial(n)
    b=str(a)
    m=len(b)
    c=0
    for i in range(m-1,-1,-1):
        if b[i]=='0':
            c+=1
        else:
            break
    print(c)

Submission status: Accepted

Solution code:
while True:
    counter=0
    n=int(input())
    if n==0:break
    a=1
    for i in range(1,n+1):
        a*=i
        
    while True:
        if a%10!=0:
            break
        else:
            a=a//10
            counter+=1
    print(counter)

Submission status: Accepted

Solution code:
import math
while True:
  n = int(input())
  if n == 0:
    break
  i = 0
  n = str(math.factorial(n))[::-1]
  while n[i] == '0':
    i += 1
  print(i)

Submission status: Accepted

Solution code:
#39 階乗の0個数 - Time Limit Exceeded

while True:
    n=int(input())
    x=1
    y=[]
    z=0
    if n==0:
        break
    for i in range(1,n+1):      #階乗
        x*=i
        #print(x)
    #print(str(x))
    for j in str(x):    #文字列
        y+=[j]
    #print(y)
    y.reverse()         #逆順
    #print(y)
    for k in y:         #0以外の値がきたら終わり
        if k=='0':
            z+=1
        elif k!=0:
            break
    print(z)

Submission status: Accepted

Solution code:
b,c=0,1
import math
while True:
    n=int(input())
    if n==0:
        break
    a=math.factorial(n)
    a=str(a)
    while True:
        if a.endswith('0'*c) is True:
            c+=1
        else:
            c-=1
            break
    print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    x=0
    while n>0:
        a=n//5
        x+=a
        n=n//5        
    print(x)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    x=1
    y=[]
    z=0
    if n==0:
        break
    
    
    for i in range(1,n+1):
        x*=i
        #print(x)
    #print(str(x))


    for j in str(x):
        y+=[j]
    
    
    #print(y)
    y.reverse()
    #print(y)
    
    for k in y:
        if k=='0':
            z+=1
        elif k!=0:
            break
    print(z)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break

    ans = 0
    while n > 0:
        ans += n // 5
        n = n // 5
    print(ans)

Submission status: Accepted

Solution code:
import math

while True:
    n = int(input())
    if n == 0:
        break
    sum=0
    m=math.factorial(n)
    m=str(m)
    for i in range(len(m)-1,-1,-1):
        if m[i]==str(0):
            sum+=1
        else:
            break
    print(sum)

Submission status: Accepted

Solution code:
import math
while True:
    n = int(input())
    if n==0: break
    else:
     x = list(str(math.factorial(n)))
     ans=0
     for i in range(-1,-len(x),-1):
      if x[i] == '0': ans+=1
      else: break
     print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    c = 0
    data = range(1,n+1)
    for i in data:
        while True:
            if i % 5 != 0:
                break
            i /= 5
            c += 1
    print(c)

Submission status: Accepted

Solution code:
import sys
import resource
sys.setrecursionlimit(20000)
def fact(n):
    if n==1:
        return 1
    else:
        return n*fact(n-1)
while True:
    n=int(input())
    if n==0:
        break
    x=fact(n)
    a=0
    while True:
        if x%10!=0:
            break
        if x%10==0:
            x=x//10
            a+=1
    print(a)

Submission status: Accepted

Solution code:
import math
while True:
    n = int(input())
    if n == 0:
        break
    x = math.factorial(n)
    cnt = 0
    while True:
        if x%5 == 0:
            x = x//5
            cnt += 1
        else:
            break
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    k = int(input())
    if k==0:
        break
    t=1
    for i in range(1,k+1):
        t *= i
    i = 0
    while t % 10 == 0:
        i+=1
        t //= 10
    print(i)

Submission status: Accepted

Solution code:
i = 0
while i < 20:
    n = int(input())
    if n == 0:
        break
    
    j = 0
    sum = 1
    while j < n:
        j = j + 1
        sum = sum*j
    #print(sum)
        
    Sum = 0
    for k in range(100000):
        if sum%10 != 0:
            break
        
        Sum = Sum + 1
        sum = sum//10
    print(Sum)

Submission status: Accepted

Solution code:
import math
N = 1
while True:
    n = int(input())
    if n == 0:
        break
    N = math.factorial(n)
    
    m = 0    
    while True:
        if N % 5 != 0:
            break
        else:
            N = N // 5
            m = m + 1
            
    print(m)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True :
    n = int(input())
    if n == 0 :
        break
    else :
        ans = 0
        for i in range(1,11):
            a = n // (5 ** i)
            ans = ans + a
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n==0:
        break
    y=1
    for i in range(1,n+1):
        y *= i
    x=0
    while True:
        if y%10 != 0:
            break
        y = y//10
        x += 1
    print(x)

Submission status: Accepted

Solution code:
while True:
    a=int(input())
    if a==0:
        break
    n=1
    i=1
    while i<=a:
        n*=i
        i+=1
    m=0
    while True:
        if int(n)%10!=0:
            break
        n=int(n)//10
        m+=1
    print(m)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    
    if n ==0 :
        break
    
    a = n//5 + n//25 + n//125 + n//625 + n//3125 + n//15625
    print(a)

Submission status: Accepted

Solution code:
while True:
    try:
        a=int(input())
        if a==0:
            pass
        else:
            x=a//5
            y=a//(5**2)
            z=a//(5**3)
            w=a//(5**4)
            u=a//(5**5)
            s=a//(5**6)
            print(x+y+z+w+u+s)
    except:
        break;

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def count(x, k):
    res = 0
    while x:
        x //= k
        res += x
    return res
def solve():
    N = int(readline())
    if N == 0:
        return False
    write("%d\n" % min(count(N, 2), count(N, 5)))
    return True
while solve():
    ...

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    a = []
    b = 0
    if n == 0:
        break
    n2 = 1
    for i in range(n,1,-1):
        n2 *= i
    c = str(n2)
    for j in range(len(c)-1,-1,-1):
        if c[j] == "0":
            b += 1
        else:
            break
    print(b)

Submission status: Accepted

Solution code:
import math

while True:
    n=int(input())
    if n==0:
        break
    x=math.factorial(n)
    i=0
    while x%10==0:
        x//=10
        i+=1
    print(i)

Submission status: Accepted

Solution code:
# coding: utf-8
# 39

while True:
    n = int(input())
    if n==0:
        break
    K = n//5 + n//25 + n//125 + n//625 + n//3125 + n//15625
    print(K)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0: break
    
    a = 0
    while n > 0:
        a += n//5
        n = n//5
    print(a)

Submission status: Accepted

Solution code:
def f(n):
    for i in range (1,n):
        n*=i
    return n
        
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=str(f(n))
        s=0
        l=len(a)
        for i in range(l-1,-1,-1):
            if a[i]=='0':
                s+=1
            else:
                break
        print(s)

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())
    if n==0:
        break
    else:
        x=math.factorial(n)
        y=str(x)
        l=len(y)
        s=0
        for i in range(l-1,-1,-1):
            if y[i]=="0":
                s+=1
            else:
                break
        print(s)

Submission status: Accepted

Solution code:
i = 0
while True:
    n = int(input())
    if n == 0:
        break
    
    j = 0
    a =[]
    while True:
        n = n//5
        a.append(n)
        if n//5 == 0:
            break
        j += 1
        
    i += 1

    print(sum(a))

Submission status: Accepted

Solution code:
while True:
    sum=1
    count=0
    n=int(input())
    if n==0:
        break
    for i in range(1,n+1):
        sum*=i
        i+=1
    while True:
        if sum%10==0:
            count+=1
            sum-=sum//10
        else:
            break
    print(count)

Submission status: Accepted

Solution code:
while True :
    x=int(input())
    if x==0 : break
    i=1
    a=1
    b=0
    while i<=x :
        a=a*i
        i=i+1
        
    while True :
        if a%10==0 :
            b=b+1
            a=a//10
        else : break
    print(b)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:
        break
    
    N = 1
    for i in range(1,n+1,1):
        N *= i
    
    zero = 0
    while True:
        if N%10 > 0:
            break
        
        N = N//10
        zero += 1
    
    print(zero)

Submission status: Accepted

Solution code:
import math
p=1
q=1
while p==1:
    o=0
    n=int(input())
    if n==0:
        break
    else:
        x=math.factorial(n)
        while q==1:
            y=x%10
            if y==0:
                o+=1
                x=x//10
            else:
                break
    print(o)

Submission status: Accepted

Solution code:
while True :
    n=int(input())
    if n==0:
        break
    s=0
    while n>0:
        s+=n//5
        n=n//5
    print(s)

Submission status: Accepted

Solution code:
import math
while True:
    n=int(input())
    k=math.factorial(n)
    if n==0:
        break
    cnt=0
    while k%5==0:
        k //=5
        cnt += 1
    
    s=0
    while k%2==0:
        k //=2
        s +=1
    if cnt > s:
        print(s)
    else:
        print(cnt)
print("", end='')

Submission status: Accepted

Solution code:
while True:
    
    t = 1; cnt=0
    
    n = int(input())
    if n==0:
        break
    
    for i in range(1,n+1):
        t *= i
    
    while (t%10==0):
        cnt += 1
        t //= 10
        
    print(cnt)

Submission status: Accepted

Solution code:
import math
while 1:
  n = int(input())
  i = 0
  if n == 0:
    break
  n=str(math.factorial(n))[::-1]
  while n[i]=='0':
    i+=1
  print(i)

Submission status: Accepted

Solution code:
while True:
    x = int(input())
    if x == 0:
        break
    a=x-1
    b=x
    while a>0:
         b *= a
         a -= 1
    c=str(b)
    d=len(c)
    
    n=1
    y=0
    while n < d:
        if c[d-n] == '0':
            y += 1
        else:
            break
        n += 1
    
    print(y)

Submission status: Accepted

Solution code:
import math

while True:
    n=int(input())
    if n==0:
        break
    
    data=str(math.factorial(n))
    i=len(data)
    
    k=0
    while data[i-1]=="0":
        k+=1
        i-=1
    print(k)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

try:
   while True:
      n = int(input())
      if n == 0: break
   
      a = 1
      for i in range(1, n + 1):
         a *= i
      
      cnt = 0
      while(a % 10 == 0):
            cnt += 1
            a //= 10
         
      print(cnt)

except EOFError:
   pass

Submission status: Accepted

Solution code:
while True:
    a=int(input())
    if a==0:break
    print(a//5+a//25+a//125+a//625+a//3125+a//15625)

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    if n == 0 :
        break
    
    S = 1
    for i in range(n) :
        S *= (i+1)
    
    ans = 0
    while True :
        if S % 10 != 0 :
            break
        else :
            S = S // 10
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    print(n//5+n//25+n//125+n//625+n//3125+n//15625)

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    
    if n == 0 :
        break
    else :
        for i in range(1, n) :
            n *= i
            
        N = str(n)
        l = len(N)
        
        s = 0
        for j in range(l - 1, -1, -1) :
            if N[j] == "0" :
                s += 1
            else :
                break
            
        print(s)

Submission status: Accepted

Solution code:
while True:
    try:
        num = int(input())
        if num == 0 :
            break
        f = 1
        ans = 0
        for i in range(num,1,-1):
            f *= i
        s = str(f)
        for i in reversed(range(0, len(s))): 
            if s[i] in '0':
                ans += 1
            else :
                break;
        print(ans)
    except EOFError:
        break

Submission status: Accepted

Solution code:
#他人の参考
def count_0(data):
    five=[5,25,125,625,3125,15625,78125]
    tmp=0
    for i in range(len(five)):
        if data>=five[i]:
            tmp+=data//five[i]
        else:
            break
    return tmp

while True:
    data=int(input())
    if data==0:
        break
    print(count_0(data))

Submission status: Accepted

Solution code:

while True:
    n = int(input())
    if n == 0:
        break
    k = 1
    for i in range(1,n+1):
        k *= i

    c = 0
    for i in str(k)[::-1]:
        if i == "0":
            c += 1
        else:
            break
    print(c)

Submission status: Accepted

Solution code:
###
### atcorder test program
###

import sys

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Prime number search
    def Pnum(self, a):
        if a == 1: return False
        for i in range(2,int(a**0.5)+1):
            if a % i == 0:
                return False
        return True

    ### Circle area
    def caria(self, r):
        return r*r*self.pi

math = math()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

#A, B, C = [int(x) for x in input().split()]

def get_input():
  N = []
  while True:
    try:
      N.append(input())
      #N.append(int(input()))
    except EOFError:
      break
  return N
 

while True:
    N = int(input())
    if N == 0:
        break
    t = 0
    for i in range(1, 7):
        t += N//(5**i)
        #print(i,N//(i**5))
    print(t)

Submission status: Accepted

Solution code:
import math
if __name__ == '__main__':

	while True:
		n = int(input())

		if n == 0:
			break

		m = math.factorial(n)
		ans = list(str(m))

		cnt = 0
		for i in reversed(ans):
			if i == "0":
				cnt += 1
			else:
				break

		print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(30000)

out_ = [0 for i in range(20000)]

def out(n):
    if n == 1:
        out_[n-1] = 0
        return out_[n-1]
    elif n % 5**6 == 0:
        out_[n-1] = 6 + out(n-1)
        return out_[n-1]
    elif n % 5**5 == 0:
        out_[n-1] = 5 + out(n-1)
        return out_[n-1]
    elif n % 5**4 == 0:
        out_[n-1] = 4 + out(n-1)
        return out_[n-1]
    elif n % 5**3 == 0:
        out_[n-1] = 3 + out(n-1)
        return out_[n-1]
    elif n % 5**2 == 0:
        out_[n-1] = 2 + out(n-1)
        return out_[n-1]
    elif n % 5**1 == 0:
        out_[n-1] = 1 + out(n-1)
        return out_[n-1]
    else:
        out_[n-1] = out(n-1)
        return out_[n-1]

out(20000)
    
while(1):
    n = int(input())
    if n == 0:
        break
    print(out_[n-1])

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    ans = 0
    while 1:
        n //= 5
        ans += n
        if n == 0:
            break

    print(ans)

Submission status: Accepted

Solution code:
from math import factorial

def process(n):
    fac = list(str(factorial(n)))
    cnt = 0
    for f in fac[::-1]:
        if f == '0':
            cnt += 1
        else:
            break
    return cnt

while True:
    n = int(input())
    if n == 0: break
    ans = process(n)
    print(ans)

Submission status: Accepted

Solution code:
memo = [0]*20010
lidx = 1

def solve(m):
    global lidx,memo
    if m < lidx: return memo[m]
    for i in range(lidx,m+1):
        memo[i] = memo[i-1]
        n = i
        while n%5 == 0:
            n/=5
            memo[i] += 1
    lidx = m
    return memo[m]


while(True):
    n = int(input())
    if not n: break
    print(solve(n))