题意: 求末尾为零的个数为m的 阶乘数分别为多少。
题解:末尾有零 肯定 2*5;
2太多了;找5就行了。
然后二分使所有区间,确定左右,依次输出。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#define LL long long
using namespace std;
const int maxn=1e9;
const int mod=1e9+7;
int dir[4]={1,6,8,9};
LL calc(LL x){
LL t=x;
int f=5,cnt=0;
while(f<=t){
cnt+=t/f;
f*=5;
}
return cnt;
}
int main(){
int n,m;
scanf("%d",&m);
int l=1,r=maxn;
while(l<=r){
int mod=(l+r)/2;
if(calc(mod)>m)
r=mod-1;
else
l=mod+1;
}
int ans1=l;
l=1,r=maxn;
while(l<=r){
int mod=(l+r)/2;
if(calc(mod)>=m)
r=mod-1;
else
l=mod+1;
}int ans2=l;
printf("%d",ans1-ans2);
for(int i=ans2;i<ans1;++i)
if(i==ans2) printf("\n%d",i);
else printf(" %d",i);
return 0;
}