cf 633b A Trivial Problem


点击打开链接


题意: 求末尾为零的个数为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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值