Light oj 1138 - Trailing Zeroes (III)
2013-05-20 14:47
393 查看
题目:Light oj 1138 - Trailing Zeroes (III)
思路:二分+暴力+求阶乘中某质因子的幂
思路:二分+暴力+求阶乘中某质因子的幂
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <stack> using namespace std; long long n; long long get_5(long long n) { long long ans=0; long long five=5; while(n>=five) { ans+=n/five; five*=5; } return ans; } long long solve(long long l,long long r) { long long mid=(l+r)/2; long long tmp=get_5(mid); if(l==r) { if(get_5(mid)==n) return mid; else return -1; } if(tmp<n) { return solve(mid+1,r); } else if(tmp>n) { return solve(l,mid); } else return mid; } int main() { int t; scanf("%d",&t); for(int cases=1;cases<=t;cases++) { scanf("%lld",&n); long long ans=solve(0,1000000000000); if(ans==-1) printf("Case %d: impossible\n",cases); else { while(get_5(ans-1)==n) ans--; printf("Case %d: %lld\n",cases,ans); } } return 0; }
相关文章推荐
- Light oj 1138 - Trailing Zeroes (III)
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
- Light OJ 1138 Trailing Zeroes (III)(n!中素数p的幂问题)
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
- LIGHT OJ 1138 - Trailing Zeroes (III)【N!后0的个数&&二分(好题)】
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
- 【Light OJ 1138 】Trailing Zeroes (III) 【二分+数学】
- Light oj 1138 - Trailing Zeroes (III) (二分)
- Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
- 【Light oj 1138 】- Trailing Zeroes (III)(二分,思维)
- Light oj 1138 - Trailing Zeroes (III)
- Light OJ 1138 - Trailing Zeroes (III)
- Light oj 1138 -Trailing Zeroes (III)
- Light OJ:1138 Trailing Zeroes (III)(二分)
- light oj 1138 - Trailing Zeroes (III)《《二分》》
- Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
- Light OJ 1138:Trailing Zeroes (III)【二分+求阶乘中某质因子的幂】
- Light oj1138 - Trailing Zeroes (III)
- Light oj-1138 Trailing Zeroes (III) (二分&数学)
- Trailing Zeroes (III) LightOJ - 1138 (数论,求n! 中某个数的个数)