C - Trailing Zeroes (III)(二分)
2024-08-27 21:30:42
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
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.
Output
For each case, print the case number and N. If no solution is found then print 'impossible'.
Sample Input
3
1
2
5
Sample Output
Case 1: 5
Case 2: 10
Case 3: impossible
AC代码
#include<stdio.h>
const int MAXN=0x3f3f3f3f;//这个要足够大才能找到10^8
int getq(int x){
int q=;
while(x){
q+=x/;
x/=;
}
return q;
}
void erfen(int n){
int l=,r=MAXN;
while(l<=r){
int mid=(l+r)>>;
if(getq(mid)>=n)r=mid-;//二分这点注意
else l=mid+;
}
if(getq(l)==n)printf("%d\n",l);
else puts("impossible");
}
int main(){
int T,Q,flot=;
scanf("%d",&T);
while(T--){
scanf("%d",&Q);
printf("Case %d: ",++flot);
erfen(Q);
}
return ;
}
最新文章
- Android混淆代码
- 你写的return null正确吗?
- 浅析for in 和for的区别
- JQuery测手速小游戏-遁地龙卷风
- arcgis server 10.2安装后,忘记Manager的用户名和密码
- Android 脚本替换PackageName
- CSAPP缓冲区溢出攻击实验(上)
- 手写归并排序(MergeSort)
- Object-C中emoji与json的问题
- mysql pdo数据库连接
- 小甲鱼python基础教程飞机大战源码及素材
- Java网络编程(二)关于Socket的一些个人想法
- AppDomain.CurrentDomain.BaseDirectory是什么
- 二维数组sort排序
- [CALayer release]: message sent to deallocated instance iOS内存过度释放问题
- Python 学习笔记之random 模块
- response提交原理(转)
- codeforces 359E Neatness(DFS+构造)
- Linux驱动虚拟地址和物理地址的映射
- sql数据库发布、订阅同步方式操作
热门文章
- 双系统重装win7和ubuntu修复win7引导方法介绍(来源百度经验)
- C++(二)— STL容器的基本用法
- linux应用之yum命令的软件源的更换(centos)
- Idea_学习_03_IDEA中使自定义类型的文件进行代码高亮识别
- PHP把时间转换成几分钟前、几小时前、几天前的几个函数、类分享
- 7_DoubleBuffer 游戏编程中的双缓存模式
- Python 爬虫 —— 文件及文件夹操作
- ACM学习历程—HDU4675 GCD of Sequence(莫比乌斯)
- 一步一步学RenderMonkey
- http头部解释