C - Trailing Zeroes (III) 二分
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
其实我特别反感这种思维题目,感觉没别的方法,没什么意思,只能这样写,还有就是我太菜了(这才是原罪)
思路::有几个0出现关键就看2和5的个数,因为是阶乘,都是乘法运算,所有要将没一个数拆开,看看他包括几个2或者几个5,,比如,10 可以分为2和5,所以只有1个5,而
25可以分为5和5 所以有两个5。。。。。在一组数中,二的数目一定比5 多吗,所以直接找5 的个数就可以啦!
记得设置为long long
AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll sum(ll x){
ll ans=;
while(x)
{
ans+=x/;
x=x/;
}
return ans;
} int main()
{
int t;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
ll n;
scanf("%lld",&n);
ll left=,right=,ans=,mid;
while(left<=right)
{
mid=(left+right)/;
if(sum(mid)==n){
ans=mid;
right=mid-;
}//找到了不一定是最小的比如11和10,阶乘都可以产生2个0
else if(sum(mid)>n){
right=mid-;
}
else {
left=mid+;
}
} if(ans>)
printf("Case %d: %lld\n",i,ans);
else
{
printf("Case %d: impossible\n",i);
}
}
return ;
}
C - Trailing Zeroes (III) 二分的更多相关文章
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
随机推荐
- TensorFlow 多元线性回归【波士顿房价】
1数据读取 1.1数据集解读 1.2引入包 %matplotlib notebook import tensorflow as tf import matplotlib.pyplot as plt i ...
- 图论-完全二叉树判定-Check Completeness of a Binary Tree
2020-02-19 13:34:28 问题描述: 问题求解: 判定方式就是采用层序遍历,对于一个完全二叉树来说,访问每个非空节点之前都不能访问过null. public boolean isComp ...
- 1036. 跟奥巴马一起编程(15) Java版
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014年底,为庆祝"计算机科学教育周"正式启动,奥巴马编写了很简单的计算机代 ...
- 干货 | Python进阶系列之学习笔记(四)
目录 Python条件判断 Python循环语句 Python循环控制 迭代器与生成器 异常 一.Python 条件判断 如果某些条件满足,才能做某件事情:条件不满足时,则不能做,这就是所谓的判断. ...
- HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm
题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...
- 浅谈SQL Server、MySQL中char,varchar,nchar,nvarchar区别
最近一次的面试中,被面试官问到varchar和nvarchar的区别,脑海里记得是定长和可变长度的区别,但却没能说出来.后来,在网上找了下网友总结的区别.在这里做个备忘录: 一,SQL Server中 ...
- 添加属于自己的python模块空间
在我们学习python的过程中会遇到很多时候,我们需要自己曾经写过的模块,它可能是一个函数或者其他的东西,,,, 下面是我的解决过程,如果你像将自己建立的文件夹当作你存放自己写的模块的地方,你需要将你 ...
- LM拟合算法
一. Levenberg-Marquardt算法 (1)y=a*e.^(-b*x)形式拟合 clear all % 计算函数f的雅克比矩阵,是解析式 syms a b y x real; f=a*e ...
- python 基本知识
1.windows下Spyder中快捷键 块注释/块反注释 Ctrl + 4/5 断点设置 F12 关闭所有 Ctrl + Shift + W 代码完成 Ctrl +空格键 条件断点 SHIFT + ...
- 关于HashSet与HashMap
package com.test; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; i ...