分治算法(1)N!个数为0的情况
题目地址 https://www.cnblogs.com/hao-tian/p/9274708.html
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<algorithm> using namespace std; long long solve(long long n) { long long sum=0; while(n>0) { n/=5LL; sum+=n; } return sum; } int main() { int n; while(~scanf("%d",&n)) { long long left=1; long long right=500000000; long long ans=500000001; while(left<=right) { int mid=(right-left)/2+left; int t=solve(mid); if(t==n&&mid<ans) { ans=mid; } if(t>n) { right=mid-1; } else if(t<n) { left=mid+1; } else { right=mid-1; } } if(ans==500000001) { printf("No solution!\n"); } else { printf("%d\n",ans); } } }
相关推荐
Ghero 2020-08-09
数据与算法之美 2020-06-10
Broadview 2020-05-16
风吹夏天 2020-02-17
yishujixiaoxiao 2020-02-02
troysps 2019-12-30
shawsun 2019-12-23
baike 2019-12-15
蜗牛慢爬的李成广 2019-12-03
蜗牛慢爬的李成广 2019-11-09
风吹夏天 2019-11-03
seekerhit 2019-10-19
微分 2014-05-25
duyifei0 2019-06-27
wonner 2017-10-05
OpenPI 2019-05-29
linergou 2016-12-26