import java.util.HashMap;
import java.util.Map;

public class Euler383 {

    private static class Key {
        long x;
        int k;
        int carryIn;

        Key(long x, int k, int carryIn) {
            this.x = x;
            this.k = k;
            this.carryIn = carryIn;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (!(o instanceof Key))
                return false;
            Key key = (Key) o;
            return x == key.x && k == key.k && carryIn == key.carryIn;
        }

        @Override
        public int hashCode() {
            int result = (int) (x ^ (x >>> 32));
            result = 31 * result + k;
            result = 31 * result + carryIn;
            return result;
        }
    }

    private static final Map<Key, Long> memo = new HashMap<>();

    private static int carryOut(int digit, int carryIn) {
        return (2 * digit + carryIn) / 5;
    }

    private static long countWithInitialCarry(long x, int k, int carryIn) {
        if (x < 0 || k < 0)
            return 0;
        if (x == 0)
            return 1;

        Key key = new Key(x, k, carryIn);
        Long cached = memo.get(key);
        if (cached != null)
            return cached;

        long ways = 0;
        for (int digit = 0; digit <= 4; ++digit) {
            if (x < digit)
                break;
            long q = (x - digit) / 5;
            int nextCarry = carryOut(digit, carryIn);
            ways += countWithInitialCarry(q, k - nextCarry, nextCarry);
        }

        memo.put(key, ways);
        return ways;
    }

    private static long countNonMultiplesOfFive(long x, int k) {
        if (x <= 0 || k < 0)
            return 0;
        long ways = 0;
        for (int digit = 1; digit <= 4; ++digit) {
            if (x < digit)
                break;
            long q = (x - digit) / 5;
            int nextCarry = carryOut(digit, 0);
            ways += countWithInitialCarry(q, k - nextCarry, nextCarry);
        }
        return ways;
    }

    public static String solve() {
        memo.clear();
        long n = 1000000000000000000L;
        long answer = 0;
        long powerOfFive = 5;

        for (int a = 1; powerOfFive <= n; ++a) {
            answer += countNonMultiplesOfFive(n / powerOfFive, a - 1);
            if (powerOfFive > n / 5)
                break;
            powerOfFive *= 5;
        }

        return String.valueOf(answer);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
