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: Wrong Answer

Solution code:
while 1:
    try:
        zero=0
        number=1
        n=int(input())
        for i in range(1,n+1):
            number*=i
            while len(str(number))>7:number=int(str(number)[1:])
            while number%10==0:
                zero+=1
                number=int(number/10)
        print(zero)
    except:break

Submission status: Wrong Answer

Solution code:
import math

while True:
    try:
        n = int(input())
    except:
        break
 
    s = 0
    fac = math.factorial(n)

    while fac % 10 == 0:
        fac = fac // 10
        s += 1

    print(s)

Submission status: Wrong Answer

Solution code:
while 1:
    try:
        n=int(raw_input())
        ans=1
        for i in range(1,n+1):
            ans*=i
        ans=str(ans)[::-1]
        cnt=0
        for i in ans:
            if i=='0':
                cnt+=1
            else:
                break
        print cnt
    except:
        break

Submission status: Wrong Answer

Solution code:
def fac(a):
    i=0
    b=5
    c=1
    while b<=a:
       i+=c*(a//b)
       b*=5
       c+=1
    print(i)
while True:
    a=input()
    if a!=0:
        fac
    else:
        break

Submission status: Wrong Answer

Solution code:
def fac(a):
    i=0
    b=5
    c=1
    while b<=a:
       i+=c*(a//b)
       b*=5
       c+=1
    print(i)
while True:
    a=int(input())
    if a!=0:
        fac(a)
    else:
        break

Submission status: Wrong Answer

Solution code:
def fac(a):
    i=0
    b=5
    c=1
    while b<=a:
       i+=c*(a//b)
       b*=5
       c+=1
    return i
while True:
    a=int(input())
    if a!=0:
        print(fac(a))
    else:
        break

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    f = 1
    for i in range(n + 1):
        f *= i + 1
    i = 0
    f_str = str(f)
    while True:
        if f_str[-1] == "0":
            i += 1
            f_str = f_str[:-1]
        else:
            break
    print(i)

Submission status: Wrong Answer

Solution code:
for e in iter(input,'0'):
 a=i=1;e=int(e)
 while 1:
  d=e//5**i
  print(i,d)
  if d:a+=d
  else:break
  i+=1
 print(a-1)

Submission status: Wrong Answer

Solution code:
for e in iter(input,'0'):
 e=int(e)
 print(sum(e//5**i for i in range(1,6)))

Submission status: Wrong Answer

Solution code:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,6)))

Submission status: Wrong Answer

Solution code:
import math
while True:
    n = int(raw_input())
    if not n:
        break
    ans = 0
    for i in range(1,n+1):
        ans += math.log10(i)
    print int(ans)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if not n:
        break
    all = 0
    for i in range(10):
        all += (i+1)*n/(5*10**i)
    print all

Submission status: Time Limit Exceeded

Solution code:
n = []
while True:
    try:
        tmp = int(input())
        if tmp == 0:
            break
        else:
            n.append(tmp)
    except EOFError:
        break

for i in range(len(n)):
    f = 1
    for j in range(1,n[i]+1):
        f *= j
    k = 0
    while True:
        if f % (10 ** k) != 0:
            print(k-1)
            break
        else:
            k += 1

Submission status: Time Limit Exceeded

Solution code:
import math
# ????????§??????????????????????????????
def fact(n):
    sum = 0
    for i in range(1,n+1):
        sum += math.log(i)
    return math.exp(sum)
def fact2(n):
    return math.sqrt(2*math.pi*n)*(n/math.exp(1))**n

n = []
while True:
    try:
        tmp = int(input())
        if tmp == 0:
            break
        else:
            n.append(tmp)
    except EOFError:
        break

for i in range(len(n)):
    f = math.factorial(n[i])
    k = 0
    while True:
        if f % (10 ** k) != 0:
            print(k-1)
            break
        else:
            k += 1

Submission status: Time Limit Exceeded

Solution code:
import math
# ????????§??????????????????????????????
def fact(n):
    sum = 0
    for i in range(1,n+1):
        sum += math.log(i)
    return math.exp(sum)
# ????????????????????§??????
def fact2(n):
    return math.sqrt(2*math.pi*n)*(n/math.exp(1))**n

def mfactorial(n, _factcache={}):
  if n not in _factcache:
    _factcache[n] = math.factorial(n)
  return _factcache[n]


n = []
while True:
    try:
        tmp = int(input())
        if tmp == 0:
            break
        else:
            n.append(tmp)
    except EOFError:
        break

for i in range(len(n)):
    f = mfactorial(n[i])
    k = 0
    while True:
        if f % (10 ** k) != 0:
            print(k-1)
            break
        else:
            k += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    cnt = 0
    _sum = 1
    if n == 0:
        break
    for i in range(1, n+1):
        _sum*=i
    while _sum  >= 10:
        if _sum % 10 != 0:
            break
        else:
            _sum /= 10
            cnt+=1
    print cnt

Submission status: Accepted

Solution code:
while 1:
    zero=0
    number=1
    n=int(input())
    if n==0:break
    for i in range(1,n+1):
        number*=i
        while len(str(number))>7:number=int(str(number)[1:])
        while number%10==0:
            zero+=1
            number=int(number/10)
    print(zero)

Submission status: Accepted

Solution code:
from math import factorial
import re
ez = re.compile(r'(0+)$')
while True:
	n = input()
	if n == 0: break
	m = ez.search(str(factorial(n)))
	if m:
		print len(m.group(1))
	else:
		print 0

Submission status: Accepted

Solution code:
import math

while True:
	n = int(input())
	if n == 0: break
	fac = str(math.factorial(n))
	print(len(fac) - len(fac.rstrip('0')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
  n = int(raw_input())
  if n==0: break
  c = 0
  while n:
    n /= 5
    c += n
  print c

Submission status: Accepted

Solution code:
def div(num,d):
    cnt = 0
    while True:
        if num % d or num == 1 : return cnt
        num /= d; cnt += 1

while True:
    n = int(raw_input())
    if n == 0: break
    n2,n5 = 0,0
    for i in xrange(2,n+1):
        n2 += div(i,2);
        n5 += div(i,5)
    print min(n2,n5)

Submission status: Accepted

Solution code:
import sys
import math

for line in sys.stdin:
    e = int(line)
    if e == 0:
        break

    a = str(math.factorial(e))
    cnt = 0
    for i in range(len(a)):
        if a[-(i+1)] == str(0):
            cnt += 1
        else:
            break
    print(cnt)

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    zero_count = 0
    while n:
        n //= 5
        zero_count += n
    print(zero_count)

Submission status: Accepted

Solution code:
import math

while True:
    n = int(input())
    if n == 0: break
 
    s = 0
    fac = math.factorial(n)

    while fac % 10 == 0:
        fac = fac // 10
        s += 1

    print(s)

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	c=0
	while n:
		n/=5
		c+=n
	print c

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    a = 1
    for i in range(n):
        a *= i+1
    lis = list(str(a))
    lis.reverse()
    for index, num in enumerate(lis):
        if num != '0':
            print index
            break

Submission status: Accepted

Solution code:
while 1:
    n=int(raw_input())
    if n==0:
        break
    ans=1
    for i in range(1,n+1):
        ans*=i
    ans=str(ans)[::-1]
    cnt=0
    for i in ans:
        if i=='0':
            cnt+=1
        else:
            break
    print cnt

Submission status: Accepted

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

Submission status: Accepted

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

import itertools


def count_zeros(n):
    result = 0
    for x in itertools.count(1):
        divisor = 5 ** x
        if divisor > n:
            break
        else:
            result += (n // divisor)
    return result


if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        else:
            print(count_zeros(n))

Submission status: Accepted

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

    d, z = 5, 0
    while d <= n:
        z += n // d
        d *= 5

    print(z)

Submission status: Accepted

Solution code:
def fac(a):
    i=0
    b=5
    while b<=a:
       i+=(a//b)
       b*=5
    return i
while True:
    a=int(input())
    if a!=0:
        print(fac(a))
    else:
        break

Submission status: Accepted

Solution code:
import math
def solve(n):
	A=list(map(int,n))
	A.reverse()
	cnt=0
	for i in A:
		if i==0:
			cnt+=1
		else:
			break
	return cnt

while True:
	n=int(input())
	if n==0:
		break
	ans=solve(str(math.factorial(n)))
	print(ans)

Submission status: Accepted

Solution code:
import math

while True:
	count = 0
	x = input()
	if x == 0:
		break
	x = str(math.factorial(x))
	x = x[::-1]
	for i in xrange(len(x)):
		if x[i] == "0":
			count += 1
		else: break
	print count

Submission status: Accepted

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

while True:
    n = int(raw_input())
    if n == 0:
        break
    x = 5
    count = 0
    while x <= n:
        count += n/x
        x *= 5
    print count

Submission status: Accepted

Solution code:
import math

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

    a = str(math.factorial(n))
    a = a[::-1]
    ans = 0

    for i in range(len(a)):
        if a[i] == '0':
            ans += 1
        else:
            break

    print(ans)

Submission status: Accepted

Solution code:
import sys

s = ""
for n in map(int, sys.stdin):
    if n == 0:
        break
    (ct, i) = (0,1)
    while True:
        r = n // ( 5 ** i )
        if r <= 0:
            break
        ct += r
        i += 1
    s += str(ct) + "\n"
print(s, end="")

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if not n:
        break
    print(sum(int(n / 5 ** i) for i in range(1, 7)))

Submission status: Accepted

Solution code:
while True:
    inp = input()
    if inp == '0': break

    num = 1
    for i in range(1, int(inp)+1):
        num = num * i

    cnt = 0
    strnum = str(num)
    while True:
        if strnum[-1] == '0':
            cnt = cnt + 1
            strnum = strnum[:-1]
        else:
            break

    print(cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100000)

def fact(i):
    if i == 0:
        return 1
    return i * fact(i - 1)

def main():
    while True:
        n = int(input())
        if n == 0:
            break

        n = str(fact(n))
        cnt = 0
        while True:
            if n[len(n) - cnt - 1] == '0':
                cnt += 1
            else:
                break

        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
while True:
    n = int(input())
    
    if n == 0:
        break
    
    fn = math.factorial(n)
    
    z_c = 0
    
    for i in str(fn)[::-1]:
        if i != "0":
            break
        else:
            z_c += 1
    
    print(z_c)

Submission status: Accepted

Solution code:
from math import factorial
from itertools import takewhile

while True:
    n = int(input())
    if n == 0: break
    print(len(list(takewhile(lambda v: v == '0', (v for v in str(factorial(n))[::-1])))))

Submission status: Accepted

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

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:
n = []
while True:
    try:
        tmp = int(input())
        if tmp == 0:
            break
        else:
            n.append(tmp)
    except EOFError:
        break

for i in range(len(n)):
    c = 0
    d = 5
    for j in range(1,n[i]+1):
        while d <= n[i]:
            c += (n[i]//d)
            d *= 5
    print(c)

Submission status: Accepted

Solution code:
import re
def fac(n):
    s = 1
    for i in range(1,n+1):
        s *= i
    return(s)

while True:
    n = int(input().strip())
    if n==0:
        break

    num_str = '%d' % fac(n)
    zeros = re.sub(r'.*[^0](0*)$', '\\1', num_str)
    print(len(zeros))

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    ans = 0
    for i in range(1,10):
        if 5 ** i > N:
            break
        ans += N // 5 ** i
    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:
# -*- coding: utf-8 -*-

import sys
import os

def factorial(n):
    a = 1
    for i in range(1, n+1):
        a *= i
    return a

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    v = factorial(n)
    s = str(v)

    counter = 0
    for i in range(len(s)-1, -1, -1):
        if s[i] == '0':
            counter += 1
        else:
            break
    print(counter)

Submission status: Accepted

Solution code:
while True :
    sample = int(input())
    if sample == 0 : break
    result = 1
    for _ in range(2, sample+1) : result *= _
    result = str(result)
    count = 0
    for _ in range(1, len(result)) :
        if result[_*-1] == '0' : count += 1
        else : break
    print(count)

Submission status: Accepted

Solution code:
import math
import itertools

while True:
    n = int(input())
    if n == 0:
        break
    result = str(math.factorial(n))
    print(len(list(itertools.takewhile(lambda x: x=="0", result[::-1]))))

Submission status: Accepted

Solution code:
def solve(data):
    from math import factorial
    fact = factorial(data)
    txt = str(fact)
    ctz = 0
    while txt.endswith('0'):
        ctz += 1
        txt = txt[:-1]
    return ctz


if __name__ == '__main__':
    # ??????????????\???
    while True:
        data = int(input())
        if data == 0:
            break

        # ????????¨???????????¨???
        result = solve(data)
        print(result)

Submission status: Accepted

Solution code:
import sys
def main():
    a = []
    for line in sys.stdin:
        hoge = int(line)
        if hoge != 0:
            a.append(hoge)
        else:
            break

    for x in range(len(a)):
        f = a[x] #factorial
        for y in range(1, a[x]):
            f *= y
        f = list(str(f))

        cnt = 0 #count
        for y in reversed(range(0, len(f))):
            if f[y] == "0":
                 cnt += 1
            else:
                break
        print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Aizu Problem 0052: Factorial II
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def factorial_trailing_zeros(N):
    ans = 0
    k = 5
    while k <= N:
        ans += N // k
        k *= 5
    return ans

    
while True:
    N = int(input())
    if N == 0:
        break
    print(factorial_trailing_zeros(N))

Submission status: Accepted

Solution code:
import math

while True:
    i = int(input())
    if i == 0:
        break
    s = str(math.factorial(i))
    c = 0
    _c = 0
    for j in list(s):
        if j == '0':
            _c += 1
        else:
            _c = 0
        if c < _c:
            c = _c
    print(c)

Submission status: Accepted

Solution code:
def fact(n):
  result = n
  for i in range(n - 1, 0, -1):
    result *= i
  return result

while True:
  n = int(input())
  if n == 0:
    break
  f = list(str(fact(n)))
  count = 0
  while True:
    check = f.pop()
    if check != '0':
      break
    else:
      count += 1
  print(count)

Submission status: Accepted

Solution code:
import math
def main():
    while True:
        _factorial = int(input())
        if _factorial == 0:
            break
        _factorial = math.factorial(_factorial)
        count = 0
        for value in (str(_factorial))[::-1]:
            if value == '0':
                count += 1
            else:
                break
        print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    f = 1
    for i in range(n):
        f *= i + 1
    i = 0
    f_str = str(f)
    while True:
        if f_str[-1] == "0":
            i += 1
            f_str = f_str[:-1]
        else:
            break
    print(i)

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:
        quit()
    a = str(math.factorial(n))
    count = 0
    for i in a[::-1]:
        if i == '0':
            count += 1
        else:
            break
    print(count)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a=i=1;e=int(e)
 while 1:
  d=e//5**i
  if d:a+=d
  else:break
  i+=1
 print(a-1)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a,i=0,1;e=int(e)
 while 1:
  d=e//5**i
  if d:a+=d
  else:break
  i+=1
 print(a)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 e=int(e)
 print(sum(e//5**i for i in range(1,7)))

Submission status: Accepted

Solution code:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,7)))

Submission status: Accepted

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

Submission status: Accepted

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

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

  ans = 0
  for i in range(n + 1):
    ans += count_five(i)
  print(ans)

Submission status: Accepted

Solution code:
def fac(n):
    if n==0 or n==1:return 1
    e=1
    for i in range(1,n+1):
        e*=i
    return e

zero=lambda t:len(t)-max([t.rfind(str(i)) for i in range(1,10)])-1
r=[]
while 1:
    p=int(input())
    if not p:break
    r.extend([zero(str(fac(p)))])
[print(i) for i in r]

Submission status: Accepted

Solution code:
# AOJ 0052: Factorial II
# Python3 2018.6.15 bal4u

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:

def calc(n):
	cnt_2=0
	cnt_5=0
	while n%2==0:
		n/=2
		cnt_2+=1

	while n%5==0:
		n/=5
		cnt_5+=1

	return cnt_2,cnt_5


while True:
	N=input()
	if N==0: quit()
	
	t2=0
	t5=0
	for i in range(N,0,-1):
		x,y=calc(i)
		t2+=x
		t5+=y
	print min(t2, t5)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
  a = int(input())
  if a ==0: break
  hoge=1
  for i in range(1,a+1):
    hoge*=i
  hoge=str(hoge)
  ans=0
  for i in range(len(hoge)-1,0,-1):
    if hoge[i] =='0':
      ans+=1
    else: break
  print ans

Submission status: Accepted

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

import re


def get_factorial(n):
    factorial = 1
    for i in xrange(1, n + 1):
        factorial = factorial * i
    return factorial


def main():
    params = []
    while 1:
        param = int(raw_input())
        if param == 0:
            break
        else:
            params.append(param)

    for param in params:
        print re.findall(r"0*$", str(get_factorial(param)))[0].__len__()

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    c = 0
    i = 5
    while i <= n:
        j = i
        while j % 5 == 0:
            j /= 5
            c += 1
        i += 5
    print c

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
import math
import itertools


def solv(n):
    fact = math.factorial(n)
    fact = list(str(fact))
    fact.reverse()
    r = 0
    for i in itertools.takewhile(lambda x: x == '0', fact):
        r += 1
    return r



while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

L = [5 ** i for i in xrange(1, 10)]

for line in stdin:
    n = int(line)
    if not n:
        break
    print(sum(n // i for i in L))

Submission status: Accepted

Solution code:
import sys


def f(n):
    re = 1
    for i in range(1,n + 1):
	re *= i
    return re


def solve():
    while True:
	n = int(raw_input())
	if n ==	0:
            break
        else:
            rr = f(n)
            ss = str(rr)
            rss = ss[::-1]
#            print rss                                                          
            c =	0
	    for k in rss:
                if k == "0":
                    c += 1
		else:
                    break
	    print c
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys


def f(n):
    re = 1
    for i in range(1,n + 1):
	re *= i
    return re


def solve():
    while True:
	n = int(raw_input())
	if n ==	0:
            break
        else:
            rr = f(n)
            ss = str(rr)
            rss = ss[::-1]
#            print rss                                                          
            for	k in range(len(rss)):
	        if rss[k] != "0":
                    print k
		    break

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,re

s = int(raw_input())
while s != 0:
	i = re.split('[1-9]',str(math.factorial(s)))
	print len(i[-1])
	s = int(raw_input())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n==0: break
    c = 0
    while n:
        n/=5
        c+=n
    print c

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n==0: break
    c = 0
    while n:
        n /= 5
        c += n
    print c

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    sm = 0
    while n != 0:
        n /= 5
        sm += n
    print sm

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n == 0:
        break
    ret = 0
    i = 1
    while 1:
        tmp = n / 5 ** i
        if tmp == 0:
            break
        ret += tmp
        i += 1
    print ret

Submission status: Accepted

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

    count = 0
    x = 5
    while x <= n:
        count += n // x
        x *= 5
    print(count)

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 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:
while True :
    n = int(input())
    if n == 0:
        break
    
    b = 1
    for i in range(n):
        b *= (i+1)
    
    a = 0
    while True :
        if b % 10 != 0:
            break
        else :
            b = b // 10
            a += 1
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
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:
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())
    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//5**2+n//5**3+n//5**4+n//5**5+n//5**6)

Submission status: Accepted

Solution code:
while True:
    x=int(input())
    if x==0:
        break
    t=1
    s=0
    while (5**t)<=x:
        s+=x//(5**t)
        t+=1
    print(s)

Submission status: Accepted

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

while True:
    n=int(input())
    if n==0:
        break
    a=0
    for i in range (6) :
        a+=n//list[i]
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
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:
while 1:
    n = int(input())
    if n == 0:
        break
    S = 1
    for i in range(n):
        S = S * (i+1)
    A = 0
    while 1:
        if S %10 !=0:
            break
        else:
            S = S //10
            A = A+1
    print(A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#(39)階数の0個数
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())
    if n == 0 :
        break
    
    S = 1
    for i in range(n) :
        S *= (i+1)
    
    a = 0
    while True :
        if S % 10 != 0 :
            break
        else :
            S = S // 10
            a += 1
    print(a)

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 % 5 != 0 :
            break
        else :
            S = S // 5
            ans += 1
    print(ans)

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:
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:
# coding: utf-8
# Your code here!
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:
import math
while True:
    n = int(input())
    if n == 0:
        break
    else:
        a = math.factorial(n)
        b = 0
        while True:
            if a%5 == 0:
                a = a//5
                b += 1
            else:
                break
        print(b)

Submission status: Accepted

Solution code:
import math

while True:
    n = int(input())
    fac = math.factorial(n)

    if n == 0:
        break
    
    i = 0

    while fac % 10 == 0:
        fac //= 10
        i += 1
    
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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