怎么对于N求有多少后导零???
因为每间隔 5 个数有一个数可以被 5 整除, 然后在这些可被 5 整除的数中, 每间隔 5 个数又有一个可以被 25 整除……一直到0
然后知道了这个就可以直接二分求值;
二分类型:0000011111111
1: 代表num(x)>=num(mid)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int Judge(int n){
int ans = 0;
while(n){
ans += n/5;
n = n/5;
}
return ans;
}
int main(){
int T, cas=1, n, num;
scanf("%d", &T);
while(T--){
scanf("%d" ,&n);
int Left = 1, Right = 5e8;
while(Left < Right){
int Mid = Left + (Right - Left) / 2;
if(Judge(Mid) >= n) Right = Mid;
else Left = Mid + 1;
}
printf("Case %d: ", cas++);
num = Judge(Left);
if(num == n)
printf("%d\n", Left);
else puts("impossible");
}
return 0;
}