(二分搜索 数论)(求阶乘里零个数对应的阶乘)light oj -- 1138
Description
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
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; #define N 0x3f3f3f3f int Num0(int n)
{
int sum = ; while(n)
{
sum += n/;
n /= ;
}
return sum;
} void Search(int w) ///二分搜索
{
int L=, R=N, mid; while(L<=R)
{
mid = (L+R)>>; if(w <= Num0(mid))
R = mid - ;
else
L = mid + ;
} if(Num0(L)==w)
printf("%d\n", L);
else
printf("impossible\n");
} int main()
{
int iCase=, n, t;
scanf("%d", &t);
while( t-- )
{
scanf("%d", &n); printf("Case %d: ", iCase++);
Search(n);
}
return ;
}
(二分搜索 数论)(求阶乘里零个数对应的阶乘)light oj -- 1138的更多相关文章
- 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) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- AJPFX:不用递归巧妙求出1000的阶乘所有零和尾部零的个数
package com.jonkey.test; import java.math.BigInteger; public class Test6 { /*** @param args* 需求:求出1 ...
- Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零
https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...
- hdu 1856 求集合里元素的个数 输出最大的个数是多少
求集合里元素的个数 输出最大的个数是多少 Sample Input41 23 45 61 641 23 45 67 8 Sample Output42 # include <iostream&g ...
- 牛客小白月赛5-D-阶乘(求n内每个数的阶乘相乘后尾数为0的个数)
题目描述 输入描述: 输入数据共一行,一个正整数n,意义如“问题描述”. 输出描述: 输出一行描述答案:一个正整数k,表示S的末尾有k个0 输入例子: 10 输出例子: 7 --> 示例1 输入 ...
- [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- Soldier and Number Game---cf546D(打表求n的素因子个数)
题目链接:http://codeforces.com/problemset/problem/546/D 题意: 给出一个n,n开始是a!/b!,每次用一个x去整除n得到新的n,最后当n变成1的时候经过 ...
- ACM数论-欧几里得与拓展欧几里得
ACM数论——欧几里得与拓展欧几里得 欧几里得算法: 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数. 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd ...
随机推荐
- 安装wamp 缺少msvcr100.dll
在一台新电脑上安装wampsever 这是百度上的解决方案,http://jingyan.baidu.com/article/0320e2c1eb49681b87507ba4.html 本人亲测 第一 ...
- Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)
ubuntu16在运行sudo apt-get update 命令后,报出错误: Clearsigned file isn't valid, got 'NOSPLIT' (does the netwo ...
- 好记性不如烂笔头--linux学习笔记9练手写个shell脚本
#!/bin/bash #auto make install httpd #by authors baker95935 #httpd define path variable H_FILES=http ...
- 529. Minesweeper
▶ 扫雷的扩展判定.已知棋盘上所有点的情况(雷区 'M',已翻开空白区 'B',未翻开空白区 'E',数字区 '1' ~ '8'),现在给定一个点击位置(一定在空白区域),若命中雷区则将被命中的 M ...
- vue组件化开发实践
前言 公司目前制作一个H5活动,特别是有一定统一结构的活动,都要码一个重复的轮子.后来接到一个基于模板的活动设计系统的需求,便有了一下的内容.首先会对使用Vue进行开发的一些前期需要的技术储备进行简单 ...
- U3D屏幕坐标,世界坐标,像素坐标之间的关系
U3D中,屏幕坐标和世界坐标单位一样,二者之间是直接的一一对应关系,不受屏幕分辨率影响.默认情况下屏幕空间画布的左下角坐标是世界原点(0,0,0),这种情形下,世界空间的点(1920,1080,任何值 ...
- Display file information in the document window
[Display file information in the document window] The status bar is located at the bottom of every d ...
- Python_06-函数与模块
1.获取当前路径 >>> import os >>> os.path() >>> os.getcwd() 'D:\\Python34' os.pa ...
- 13.Roman to Integer (HashTable)
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- Qt Image Water Marker
QString str = "input.jpg"; if(!img.load(str)){ return; } QImage mark(img.width()/2,img.hei ...