sgu 154 Factorial
来源:互联网 发布:热重分析软件下载 编辑:程序博客网 时间:2024/06/06 13:59
154. Factorial
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
memory limit per test: 4096 KB
input: standard input
output: standard output
output: standard output
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.
Input
One number Q written in the input (0<=Q<=10^8).
Output
Write "No solution", if there is no such number N, and N otherwise.
Sample test(s)
Input
2
Output
10
问是否存在整数n,使得n!的末尾恰有Q个0.有的话输出最小满足条件的n
n!尾数0的个数就是 [n/5] + [n/25] + [n/5^3]+.....
我们可以二分枚举n ,然后做判断,不断缩小范围。。
知道AC。
贴个代码:
#include<iostream>#include<cstring>#include<cstdio>#include<set>#include<algorithm>#include<vector>#include<cstdlib>#define inf 0xfffffff#define CLR(a,b) memset((a),(b),sizeof((a)))#define FOR(a,b) for(int a=1;a<=(b);(a)++)using namespace std;int const nMax = 1010;int const base = 10;typedef long long LL;typedef pair<LL,LL> pij;// std::ios::sync_with_stdio(false);long long n;LL f(LL a){ LL ans=0; LL t=5; while(a/t){ ans+=(a/t); t*=5; } return ans;}int main(){ LL l,r; l=0,r=450000000; cin>>n; LL ans=r; while(l<=r){ LL mid=(l+r)>>1; LL p=f(mid); // printf("%lld %lld\n",mid,p); if(p==n){ if(ans>mid) ans=mid; r=mid-1; }else if(p>n){ r=mid-1; }else { l=mid+1; } } if(ans==0)ans=1; if(ans==450000000){ printf("No solution\n"); }else printf("%I64d\n",ans); return 0;}
- sgu 154 Factorial
- SGU 154-Factorial
- SGU - 154 - Factorial (数论)
- SGU-154 Factorial (末尾0 & 三分)
- SGU 154 Factorial(数论+二分)
- SGU 154. Factorial
- SGU 154. Factorial
- SGU - 154 Factorial(阶乘素因子次数的逆问题)
- SSU 154 Factorial(二分)
- Factorial!
- Factorial
- Factorial
- factorial
- Factorial
- Factorial
- Factorial
- Factorial
- Factorial
- 黑马程序员_java集合框架
- Contiki2.6 Makefile.include注解【图文】
- mysql oracle sqlServer
- hdu3642 线段树长方体体积交
- Clojure Support in Cloud Foundry
- sgu 154 Factorial
- Codeforces Round #148 (Div. 2)
- 开始使用CSDN博客
- 再配置Linux字体
- firefox 14 vim化——Pentadactyl
- putty详细使用说明 (windows下)
- codeforces 148 div1
- Compass和Lucene的一些资料
- 【Visual C++】游戏开发笔记三十一 回归季:游戏开发资料整理打包下载&专栏行文思路整理