Problem:


Score : 500 points

Problem Statement

For an integer n not less than 0, let us define f(n) as follows:

f(n) = 1 (if n < 2)

f(n) = n f(n-2) (if n \geq 2)

Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

Constraints

0 \leq N \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of trailing zeros in the decimal notation of f(N).

Sample Input 1

12

Sample Output 1

1

f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.

Sample Input 2

5

Sample Output 2

0

f(5) = 5 × 3 × 1 = 15, which has no trailing zeros.

Sample Input 3

1000000000000000000

Sample Output 3

124999999999999995



Sample input:
12


Sample output:
1

Submission status: Runtime Error

Solution code:
n=int(input())

def f(n):
  if n<2:
    return 1
  else:
    return n*f(n-2)

print(f(n))

Submission status: Runtime Error

Solution code:
from functools import reduce
n=int(input())

total=reduce(lambda x,y:x*y, range(n,0,-2))
exp=1
while total%(10**exp)==0:
    exp+=1

print(exp-1)

Submission status: Runtime Error

Solution code:
N = int(input())
def f(n):
    if n<2:
        return 1
    else:
        return n*f(n-2)
count = 0
A = f(N)
while True:
    if A % 10 == 0:
        count += 1
    else:
        break
    A /= 10
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
total_breaks = 0
position = 0
for i in range(1, n + 1):
    try:
        breaks = a[position::].index(i)
        total_breaks += breaks
        position = position + breaks + 1
    except ValueError:
        if position == 0:
            total_breaks = -1
            break
        else:
            total_breaks = total_breaks + n - position
            break
print(total_breaks)

Submission status: Runtime Error

Solution code:
n = int(input())

if n < 2:
    print(1)
    
else:
    if n % 2 == 0:
        a = n//2
    else:
        a = n//2 + 1

c = 0
m = 1
for i in range(a):
    m = (n-c)*m
    c -= 2

m = str(m)
zlist = list(m)
print(zlist.count("0"))

Submission status: Runtime Error

Solution code:
def f(n):
    if n < 2:
        return 1
    
    return n * f( n - 2 )


n = int(input())
o = f(n)

count = 0
while o % 10 == 0:
    count+=1
    o = o // 10

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 1000000000000000000:
    print(124999999999999995)
else:
    cnt = 0
    dp = [0]*(n+1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2,n+1):
        dp[i] = i*dp[i-2]
    ans = dp[n]
    l = -1
    while str(ans)[l] == '0':
        cnt+=1
        l-=1
    print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
NN = N-2
while NN >= 2:
    N *= NN
    NN -= 2
NNN = str(N)
cntt = 1
cnt = 0
while 1: 
    if NNN[len(NNN) - cntt] != '0':
        break
    else:
        cnt+=1
        cntt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
if n % 2 == 1:
  print(0)
  quit()

l = int(math.log10(n))+1
cnt = 0
for i in range(1,10*l):
  cnt += (n // 5 ** i) // 2
print(cnt)

Submission status: Runtime Error

Solution code:
N=int(input())
if N%2==1:
  print(0)
else:
  n=N//2
  A=n
  a=0
  b=0
  while A>=5**a:
    a+=1
  while A>=2**b:
    b+=1

cntfive=0  
cnttwo=0
for i in range(1,a):
  cntfive+=n//(5**i)
for j in range(1,b):
  cnttwo+=n//(2**j)

ans=min(cntfive,cnttwo+n)
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

int main()
{

    ll n, tmp, pau, ans = 0;
    cin >> n;

    for (ll i = 1; i < 30; i++)
    {
        pau = 1;
        rep(j, i)
        {
            pau *= 5;
        }
        pau = 2 * pau;
        if (n >= pau)
        {
            tmp = i;
            ans += n / pau;
        }
    }
    cout << ans << endl;
    // ll n, tmp, ans = 0;
    // n = 12;
    // tmp = n;
    // while (tmp >= 2)
    // {
    //     ans *= tmp;
    //     tmp -= 2;
    // }
    // cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
if n % 2 == 1:
    print(0)
else:
    ans = 0
    n //= 2
    frac = 1
    for i in range(1, 26):
        frac *= 5
        ans += n // frac
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

def recursiveFactorial(n):
    if n < 2:
        return 1
    else :
        return n * recursiveFactorial(n - 2)
    
num = recursiveFactorial(N)

number = str(num)

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

print(cnt)

Submission status: Runtime Error

Solution code:
n  = int(input())
mod = 1e9+7
d  = 10
xs = []

while d <= n:
	xs.append(n // d)
	d *= 10
    d %=mod

c = 0
k = 1
y = 0

for x in xs:
	c += (k - y) * x
    c %=mod
	k += 1
	y  = y * 10 + 1
    y %=mod
    

print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
import numpy as np
if N<=10:
  if N==7 or N==9 or N==10:
    print(1)
    exit()
  else:
    print(0)
    exit()
if N%2==0:
  A=[2]
else:
  A=[1]
i=A[0]+2
while i<=N:
  A.append(i)
  i+=2
A=np.array(A)
a=0
m=1
while len(A)!=0:
    A=A[A%(5**m)==0]
    a+=len(A)
    m+=1
print(a)

Submission status: Runtime Error

Solution code:
N=int(input())
if N%10==1:
  return (N-1)/10
elif N%10==2:
  return (N-2)/10
elif N%10==3:
  return (N-3)/10
elif N%10==4:
  return (N-4)/10
elif N%10==5:
  return ((N-5)/10)+1
elif N%10==6:
  return (N-6)/10
elif N%10==7:
  return ((N-7)/10)+1
elif N%10==8:
  return (N-8)/10
else:
  return (N-9)/10

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

def f(n):
    if n < 2:
        return 1
    else:
        return n*f(n-2)

def matubi(n):
    ans = 0
    while n%10 == 0:
        ans += 1
        n /= 10
    return ans

n = int(input())
print(matubi(f(n)))

Submission status: Runtime Error

Solution code:
from math import log
n = int(input())
if n % 2 == 1:
    print(0)
else:
    m = n // 2
    total = 0
    for p in range(1, int(log(m, 5)) + 1):
        total += m // (5 ** p)
    print(total)

Submission status: Runtime Error

Solution code:
s = input().split()
N = int(s[0])
count=0
i=1
if N%2==0:
    while i <= int(math.log(N, 5)):
        count+=int(N/(5**i)/2)
        i+=1
    print(count)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
if n%2==1:
  print(0)
else:
  if n == 0:
    print(1)
    exit()
  ans = 0
  n //= 2
  x = 5
  while n//x > 0:
    ans += n//x;
    x *= 5
print(ans)

Submission status: Runtime Error

Solution code:
from math import log
n = int(input(n))
if n % 2 == 1:
    print(0)
else:
    m = n // 2
    total = 0
    for p in range(1, int(log(m, 5)) + 1):
        total += m // (5 ** p)
    print(total)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

import sys

sys.setrecursionlimit(10000)

N = int(input())

cnt = 0


@lru_cache(maxsize=10000)
def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n - 2)


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

print(cnt)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

# import sys

# sys.setrecursionlimit(1000)

N = int(input())

cnt = 0


@lru_cache(maxsize=1000)
def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n - 2)


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

print(cnt)

Submission status: Runtime Error

Solution code:
import math
N = int(input())

k = 0
if N%2 ==0:
  n = N//2
  i = 1
  while n　>= 5**i :
    k += math.floor(n /(5**i))
    i += 1

print(k)

Submission status: Runtime Error

Solution code:

n=int(input())

def doublefactorial(n): 
    if (n == 0 or n == 1): 
        return 1
    return n * doublefactorial(n - 2)

s=str(doublefactorial(n))[::-1]
zeros=0
for c in s:
    if c=='0':zeros+=1
    else:break
print(zeros)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

ans = np.prod(range(int(input()), 0, -2))

cnt = 0

for s in str(ans)[-1::-1]:
  if int(s) == 0:
    cnt += 1
  else:
    break
    
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def f(n):
    if n < 2:
        return 1
    else:
        return n*f(n-2)

def matubi(n):
    ans = 0
    while n%10 == 0:
        ans += 1
        n /= 10
    return ans

n = int(input())
print(matubi(f(n)))

Submission status: Runtime Error

Solution code:
n = int(input())
if n%2==1:
  print(0)
else:
  ans = 0
  n //= 2
  x = 5
  while n//x > 0:
    ans += n//x;
    x *= 5
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

def func(n):
    if n < 2:
        return 1
    if n >= 2:
        return n * func(n - 2)

count = 0
for s in reversed(str(func(int(input())))):
    if int(s) != 0:
        break
    else:
        int(s) == 0
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
 
def doublefactorial(n): 

	if (n == 0 or n == 1): 
		return 1; 
	return n * doublefactorial(n - 2)

j=doublefactorial(int(input()))
j=str(j)
p=len(j) - len(j.rstrip('0'))
print(p)

Submission status: Runtime Error

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

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

def func(x):
    if x <= 1:
        return 1
    else:
        return x * func(x-2)

N = int(input())

f = 0
ans = 0

if N >= 2:
    f = N * func(N-2)
    fstr = str(f)
    for i in range(len(fstr)):
        if fstr[len(fstr)-i-1] == str(0):
            ans = ans + 1
        else:
            break

print(ans)

Submission status: Runtime Error

Solution code:
d = {0: 1, 1: 1}


def main():
    n = int(input())
    m = str(df(n))
    count = 0
    if m[-1] != '0':
        print(0)
    else:
        while (m[-1] == '0'):
            m = m[:-1]
            count += 1
        print(count)


def df(n):
    if n in d:
        return d[n]
    else:
        temp = n*df(n-2)
        d[n] = temp
        return temp


df(1000)
main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
n = int(input())
count = 0
def f(n) :
    if n < 2 :
        return 1
    else:
        return n * f(n-2)

a = f(n)
while a % 10 == 0:
    count+= 1
    a //= 10

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())

def a(n):
  if n<2:
    return 1
  elif n>=2:
    return n*a(n-2)

an = a(n)
flag=1
cnt=0
#print(a(n))
while flag:
  an,mod=divmod(an, 10)
  cnt+=1
  if mod>0:
    cnt-=1
    flag=0
print(cnt)

Submission status: Runtime Error

Solution code:
def f(n):
    if n < 2:
        return 1
    else:
        return n*f(n-2)

def matubi(n):
    ans = 0
    while n%10 == 0:
        ans += 1
        n /= 10
    return ans

n = int(input())
print(matubi(f(n)))

Submission status: Runtime Error

Solution code:
n = int(input())


def f()
def f(num):
    num = num - int(str(num)[-1])
    count = 0
    i = 1
    while True:
        if ((5 ** i) * (2)) > num:
            break
        count += (num // ((5 ** i) * (2)))
        i += 1
    return count


# 偶数 => 出てくる5の個数
# 奇数 => 0
if n % 2 == 1:
    print(0)
    exit()
else:
    print(f(n))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())

if n % 2 == 1:
    print(0)
else:
    count = 0
    while n > 1:
        m = n
        if m % 5 == 0
            while m % 5 == 0:
                m = m // 5
                count += 1
        n -= 2
    print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
c5=0
c2=0
if N%2==0:
  print(0)
else:
  Nlis=[2i for i in range(1,int(N/2)+1)]
  while(Nlis!=[0 for i in range(N)]):
    for i in range(N):
      if Nlis[i]%2==0:
        c2+=1
        Nlis[i]=Nlis[i]//2
      else:
        Nlis[i]=0
  Nlis=[2i for i in range(1,int(N/2)+1)]
  while(Nlis!=[0 for i in range(N)]):
    for i in range(N):
      if Nlis[i]%5==0:
        c5+=1
        Nlis[i]=Nlis[i]//5
      else:
        Nlis[i]=0

Submission status: Runtime Error

Solution code:
N=int(input())

from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 8)

def nfib(n):
    if n < 2:
        return 1
    else:
        return n * nfib(n-2)

@lru_cache(maxsize=None)
def nfib_memo(n):
    if n < 2:
        return 1
    else:
        return n * nfib(n-2)

cnt = 0
for s in str(nfib_memo(N)):
    if s == '0':
        cnt += 1
    else:
        cnt = 0
print(cnt)

Submission status: Runtime Error

Solution code:
import math


def solve_even(n):
    assert(n % 2 == 0)
    k = n // 2
    return leg(k)


def leg(k):
    return sum(k // 5 ** i for i in range(1, int(math.log(k) / math.log(5)) + 1))


n = int(input())

if n % 2 == 0:
    print(solve_even(n))
else:
    if n == 1:
        print(0)
    else:
        print(solve_even(n + 1) - leg(n // 2))

# (2k + 1)!! = (2k + 2)! / (2^(k+1)*(k+1)!)

Submission status: Runtime Error

Solution code:
N = int(input())

def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n-2)

num = f(N)

zero = 0
while True:
    if num % 10 == 0:
        zero += 1
        num /= 10
    else:
        break
print(zero)

Submission status: Runtime Error

Solution code:
import math
def main():
    N = int(input())
    if N % 2 == 1:
        return 0
    t = int(math.log(N, 5))
    a = 0
    for i in range(1, t+1):
        a += N // (2 * (5 ** i))
    return a
print(main())

Submission status: Runtime Error

Solution code:
import math

n = int(input())
if n % 2 == 0:
  m = math.ceil(math.log(n, 5))

  ans = 0
  for i in range(1, m+1):
    ans += n // (2*5**i)
  print(ans)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import math
N = int(input())

if N % 2 != 0:
    print(0)
else:
    n = N // 10
    ans = n
    for i in range(1,int(math.log(n, 5) + 1)):
        ans += n // (5 ** i)
    print(ans)

Submission status: Runtime Error

Solution code:
[A, B] = [int(s) for s in input().split()]

def gcd(a, b):
    return b if a == 0 else gcd(b%a, a)
print(int(A*B/gcd(A, B)))

Submission status: Runtime Error

Solution code:
N=int(input())

if N%2==1:
    print(0)
    sys.exit()


N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)

Submission status: Runtime Error

Solution code:
N = int(input())
d = [0 for i in range(19)]
if N % 2 == 1:
    ans = 0
f = 0
else:
    for i in range(18):
        x = 18 - i
        y = 10**y
        a = N // y
        d[x] = a - f
        f = a
    ans = 0
    for i in range(1,19):
        ans += (d[i]*i)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
if n%2==1:
  print(0)
else:
  l=n//2
  k=0
  while l>=5:
    l/=5
    k+=1
  #print(k)
  c=0
  for i in range(1,k+1):
    c+=n//(2*5**i)
  print(c

Submission status: Runtime Error

Solution code:
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()


N = int(input())
if N % 2 == 1:
    print(0)
else:
    k = N // 2
    a = int(math.log(k, 5))
    ans = 0
    for i in range(1, a + 1):
        ans += k // (5 ** i)
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

if n %2 ==1:
  print(0)
else:
  mod = 10
  ans = x = n//mod
  
  while(x>0):
    mod *= 5
    x = n//mod
    ans+=x
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

if N%2==1:
    print(0)
else:
    ans=0
    div=10
    while N//div>0:
        ans+=N//div
        div*=5
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

if N%2==1:
  print(0)
else:
  ans = 0
  m = 5
  n = 1
  while m<=N:
    c = N//m
    c = c//2
    ans += c
    m *= 5
print(ans)

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

def make_divisors(n): #約数列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = onem()

if n % 2 == 1:
    print(0)
else:
    kkk = n // 10
    po = 10
    while True:
        po *= 5
        if po > n:
            break
        kkk += n//po

print(kkk)

Submission status: Runtime Error

Solution code:
N = int(input())

if N % 2 == 1:
    print(0)
else:
    N = N//2
    ans = 0
    while N != 0:
        ans += N // 5
        N = N // 5
        
print(ans)