参考链接

https://zhuanlan.zhihu.com/p/648041720

https://www.luogu.com.cn/problem/P2388

alt

alt 二者结合起来先暴力n!!,然后求解即可

#include<bits/stdc++.h>

using namespace std;
#define LL __int128
#define ll long long

inline __int128 read(){
    __int128 x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

LL solve(LL n) {
    LL ans = 0;
    if (n & 1) {
        LL k = 5;
        while (k <= n) {
            ans += ((n / k) + 1) / 2;
            k *= 5;
        }
    }
    else
    {
        LL k = 5;
        while (k <= n) {
            ans += (n / k) / 2;
            k *= 5;
        }
    }
    for(LL j = 5; j <= n; j *= 5)
    {
        ans += j * (n / j) * (n / j - 1) >> 1;
        ans += (n / j) * (n % j + 1);
    }
    
    
    return ans / 2;
}

void print(LL x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    LL n;
    n = read();
    print(solve(n));
}