Links: http://codeforces.com/problemset/problem/1114/C
Meaning of the questions: given number $ n $ and $ b $, $ n $ and asked how many of the leading zeros in $ b $ ary!.
This question was written as if winter will not like, and then did not remember writing that today want to see that this problem of F Road gave way cut.
Idea: to have the lead after the zero it means that $ n $ divisible by $ b $, then how much is seeking $ n $ $ b $ factorial which has the power of!!. First break it down $ b $ and ask what the prime factors of the number. Out of $ n! $ Ask about the power of well-established factor is how much, taking the smallest ratio is the answer.
Note seeking $ n! $ Of the powers of the prime factors which may overflow, multiplication division can become.
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 10; pair<ll, ll> p[N]; int cnt; ll C(ll x, ll p) { ll res = 0; ll temp = p; while (x >= temp) { res += x / temp; if (x / p < temp) break; temp *= p; } return res; } int main() { ll n, b; scanf("%lld%lld", &n, &b); for (ll i = 2; i * i <= b; i++) { if (b % i == 0) { p[++cnt].first = i; p[cnt].second = 0; while (b % i == 0) { p[cnt].second++; b /= i; } } } if (b != 1) { p[++cnt].first = b; p[cnt].second = 1; } ll ans = 1e18; for (int i = 1; i <= cnt; i++) { ll res = C(n, p[i].first); ans = min(ans, res / p[i].second); } cout << ans << '\n'; return 0; }