C
来源:互联网 发布:java 设置时区 编辑:程序博客网 时间:2024/06/16 17:19
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 starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.
For each case, print the case number and N. If no solution is found then print 'impossible'.
3
1
2
5
Case 1: 5
Case 2: 10
Case 3: impossible
注意:数据一定要足够大,否则,你懂得。。。。#include <iostream>#include <cstdio>int app(long long int n){long long ans=0;while(n>0){ans+=n/5;n/=5;}return ans;}int main(){ long long int t,w; scanf("%lld",&t); w=t; while(t--) { long long int q,l,r,mid; scanf("%lld",&q); l=1; r=2100000000; long long sum=0; while(l<=r) { mid=(l+r)/2; if(app(mid)==q) { sum=mid; r=mid-1;} elseif(app(mid)>q) { r=mid-1;}else { l=mid+1;} }if(sum>0)printf("Case %lld: %lld\n",w-t,sum);else printf("Case %lld: impossible\n",w-t);}return 0;}
阅读全文
0 0
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- HDU4135 Co-prime【容斥原理】3方法
- MySQL数据表导入Excel模板
- Android 的常用控件(下拉,日期,时间,单项,多项)
- Vue.js学习笔记:v-if条件渲染与v-show区别
- 学习笔记
- C
- 更改Tomcat日志路径
- 2017全国大学生信安赛 easyheap
- 影响关键词排名稳定的因素有哪些?
- 前端基础学习之CSS样式
- 【bzoj1334】[Baltic2008]Elect
- OpenWrt移植Apache2 apr 到MT7620N
- 【ETL】拉链表算法
- mysql binlog日志及mysqlbinlog操作详解