题目描述:

  假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少?

解题思路:

  由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n=2^x=5^y,可知x<<y。

所以我们可以直接根据因子5的个数,算阶乘末尾的零的个数。1<=Q<=10^8,所以可以用二分快速求解。

代码:

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
LL find_zeros (LL n)
{
LL ans = ;
while (n)
{
ans += n / ;
n /= ;
}
return ans;
}
int main ()
{
LL t, n, l = ;
scanf ("%lld", &t);
while (t --)
{
scanf ("%lld", &n);
LL low, high, mid;
low = ;
high = ;
while (low <= high)
{
mid = (low + high) / ;
LL num = find_zeros(mid);
if (num < n)
low = mid + ;
if (num >= n)//求出来的n要是最小的,所以这里不能直接返回
high = mid - ;
}
if (find_zeros(low) == n)
printf ("Case %lld: %lld\n", l++, low);
else
printf ("Case %lld: impossible\n", l++);
}
return ;
}

LightOj 1138 Trailing Zeroes (III)的更多相关文章

  1. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  2. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...

  3. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  4. LightOJ 1138 Trailing Zeroes (III) 打表

    就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...

  5. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  6. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  7. 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 ...

  8. 1138 - Trailing Zeroes (III) 二分

    1138 - Trailing Zeroes (III)   You task is to find minimal natural number N, so that N! contains exa ...

  9. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

随机推荐

  1. how to read openstack code: Core plugin and resource extension

    本章我们将写一个自己的core plugin 和一个resource extension来加深理解.(阅读本文的前提是你已经理解了restful以及stevedore等内容) 什么是 core plu ...

  2. 【转】PLSQL_标准删除的方式Delete/Drop/Truncate区别和比较

  3. 谁是性能杀手?Kafka多Topic下启用SSL时延增大问题分析

    问题背景 项目中将Kafka接口进行RESTful封装,在使用RESTful接口进行性能测试时,发现Topic数增多后,开启SSL与非SSL进行测试,发现开启SSL后性能下降得厉害.例如600个Top ...

  4. Codeforces 104C Cthulhu dfs暴力 || 点双连通缩点

    题目链接:点击打开链接 题意: 给定n个点m条边的无向图 问图中是否存在 有且仅有一个简单环和一些树,且这些树的root都在这个简单环上. 瞎写了个点双. . == #include <stdi ...

  5. Oracle学习(18)【DBA向】:分布式数据库

    分布式数据库 什么是分布数据库? l数据物理上被存放在网络的多个节点上,逻辑上是一个总体. 分布式数据库的独立性 l分布数据的独立性指用户不必关心数据怎样切割和存储,仅仅需关心他须要什么数据. Ora ...

  6. Node-webkit 介绍

    什么是Node-webkit ? Node-webkit 是Intelproject师rogerwang写的一个基于node.js和chromium的应用程序执行环境,通过node-webkit,我们 ...

  7. bzoj3109【CQOI2013】新数独

    3109: [cqoi2013]新数独 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 365  Solved: 229 [Submit][Statu ...

  8. 理解static关键字

    1.static 变量是类变量,通过类名引用. 2.static 方法不需要针对某个对象进行操作,其运行结果仅仅与输入的参数有关,调用时直接类名引用. 3.static 方法不能对非静态成员进行访问. ...

  9. reverse proxy and forward proxy

    1 什么是forward proxy 一句话,client的proxy就是forward proxy. 2 什么是reverse proxy 一句话,server的proxy就是reverse pro ...

  10. linux 监控进程所消耗的资源(内存),达到阈值(绝对值、相对值)后,将其杀死

    监控某个python进程是否存在,如不存在则启动 #!/bin/bashwhile [ 1 ]do #打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v " ...