题意:
问是否存在N,其阶乘结果尾是否恰好有n个0;
思路:
很容易想到,就是要找n的阶乘含有因子10的个数,也就是找因子 2, 5 的个数,又因为 2 的个数多于 5,我们只需要查找5的个数就好了
这里包含了 求n的阶乘含有因子5的个数 的方法
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1000 + 7, maxd = 400000015, mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
int num(int x) {
int res = 0;
while(x) {
res += (x / 5);
x /= 5;
}
return res;
}
int main() {
int T;
scanf("%d", &T);
for(int tt = 1; tt <= T; ++tt) {
int n; scanf("%d", &n);
int l_ = 5, r_ = maxd;
int ans = -1;
while(l_ <= r_) {
int mid = (l_ + r_) / 2;
int t = num(mid);
if(t == n) { ans = mid; r_ = mid - 1; }
else if(t < n) {
l_ = mid + 1;
}
else {
r_ = mid - 1;
}
}
if(ans != -1) printf("Case %d: %d\n", tt, ans);
else printf("Case %d: impossible\n", tt);
//printf("%d\n", num(n));
}
return 0;
}