This page is still under construction.

Parts of this page are still being built. What you see may change.

Factorials with an even number of trailing zeroes

Time limit1sMemory limit128 MB

Summary
Count how many k from 0 to n have a factorial ending in an even number of zeros for each query.
Level

Medium7 of 10

Topics
Number theory, Dynamic programming, Math
Solved
No attempts yet

Problem

The factorial of a positive integer nn is written n!n! and is defined like this.

n!=1×2×3×4×⋯×(n−1)×nn! = 1 \times 2 \times 3 \times 4 \times \cdots \times (n-1) \times n

The value of 0!0! is taken to be 11. As nn grows, n!n! grows very quickly. Here are a few values.

  • 0!=10! = 1
  • 1!=11! = 1
  • 2!=22! = 2
  • 3!=63! = 6
  • 4!=244! = 24
  • 5!=1205! = 120
  • 10!=362880010! = 3628800
  • 14!=8717829120014! = 87178291200
  • 18!=640237370572800018! = 6402373705728000
  • 22!=112400072777760768000022! = 1124000727777607680000

For some nn the number of trailing zeroes of n!n! is odd. That happens for 5!5! and 18!18!. For other nn it is even, as with 0!0!, 10!10! and 22!22!.

Given nn, count how many of 0!,1!,2!,3!,…,(n−1)!,n!0!, 1!, 2!, 3!, \ldots, (n-1)!, n! have an even number of trailing zeroes.

Input

Standard input holds one query per line, at most 10001000 of them. Each query is a single integer nn (0≤n≤10180 \le n \le 10^{18}).

The last line holds −1-1. That line is not a query, it only marks the end of the input.

Output

Print one line per query. The line holds how many of 0!,1!,2!,3!,…,n!0!, 1!, 2!, 3!, \ldots, n! have an even number of trailing zeroes.

Print nothing for the −1-1 that ends the input.

Examples1

  1. Example 1

    Input
    2
    3
    10
    100
    1000
    2000
    3000
    10000
    100000
    200000
    -1
    
    Expected output
    3
    4
    6
    61
    525
    1050
    1551
    5050
    50250
    100126