Trailing Zeroes (III) -;lightoj 1138】的更多相关文章

Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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 ex…
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1138 Description You task is to find minimal natural number N, so t…
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)">Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the…
1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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.…
1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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.…
/** 题目:Trailing Zeroes (III) 链接:https://vjudge.net/contest/154246#problem/N 题意:假设n!后面有x个0.现在要求的是,给定x,要求最小的n: 思路:判断一个n!后面有多少个0,通过n/5+n/25+n/125+... */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #includ…
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf">PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactl…
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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. F…
1138 - 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 sta…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出impossible 可以用二分求结果,重点是求一个数的阶乘中末尾含有0的个数,一定和因子5和2的个数有关,因子为2的明显比5多,所以我们只需要求一个数的阶乘的因子中一共有多少个5即可; LL Find(LL x) { LL ans = ; while(x) { ans += x/; x /= ;…
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)…
题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于0是由5×2 出现的,2的个数比5多故计算5的个数就可以. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex>…
Time Limit: 2 second(s) Memory Limit: 32 MB 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. In…
就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algori…
题目描述: 假设有一个数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>…
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_42279796/article/details/88218061…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知道N!里5(包括5的倍数)的个数比2(包括2的倍数)的个数多,所以1对应5!,2对应10!... 而末尾0的个数与N成正比,1e8对应的N最大是400000015.我用二分查询N对应末尾0的个数,要是计算出来末尾0的个数比给你的数还大就L=mid+1,否则就R=mid. #include <iost…
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)…
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)…
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)…
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)…
题目链接:https://cn.vjudge.net/problem/ 题意 找一个最小的正整数n 使得n!有a个零 思路 就是有几个因数10呗 考虑到10==2*5,也就是说找n!因数5有几个 数据量略大(N<=1e8),打表之类的O(N)算法是直接不可以 分析到这里,可能的算法也就是二分了 找了找很久规律,发现可以有O(log5(n))的方法确定n!的因数5的个数 于是有二分 代码 // binary search // [f(m)<n, f(m)=n, f(m)>n] // [l,…
嗯... 题目链接:https://vjudge.net/contest/318956#problem/E 这道题是二分答案+数论,但首先是数论,否则你不知如何二分... 首先关于一个阶乘的结果最后会出现0(即10),肯定是由2 * 5所造成的,而对于正整数 N,在[0, N]范围内,质因子中含有 2 的总是会比质因子含有 5 的要多.所以,只要需要知道质因数含有 5 的数字有多少个,即可知道末尾连续出现 0 的个数有多少... 然后我们进行二分答案,从1~5e8 + 5(一定要足够大!)进行二…
1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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.…
题目描述: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 解题思路: 这个题目给的评级是easy,其实只要想到要求n!中0的个数,能够得到0的只有:2,4,5,10,100....而这里面又以5最为稀缺,所以说我们可以得出阶乘的最终结果中的0的数量等于因子中5的数量,比如说10,阶乘含两个0,…
Given an integer n, return the number of trailing zeroes in n!. 问题描述:给出一个正整数n,计算n!结构后面有几个0.要求:在多项式时间中完成算法. 常规思路:计算n!,然后统计一下后面有几个0,但是这种算法一想就知道肯定会超出时间限制. 巧妙思路:相乘得0,则只有2*5相乘能得到0:而0的个数也只会与2.5的个数有关,而一个数一定能分解成1^x1+2^x2+3^x3+5^x5+7^x7+……的形式,而且2的幂方数一定比5的幂方数多…
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 分析 Note中提示让用对数的时间复杂度求解,那么如果粗暴的算出N的阶乘然后看末尾0的个数是不可能的. 所以仔细分析,N! = 1 * 2 * 3 * ... * N 而末尾0的个数只与这些乘数中5和2的个数有关,因为每出现一对5和2就会产生…
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. Credits:Special thanks to @ts for adding this problem and creating all test cases. 这道题并没有什么难度,是让求一个数的阶乘末尾0的个数,也就是要找乘数中10的个数,…
Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this question in a real interview? Yes Example 11! = 39916800, so the out should be 2 Challenge O(log N) time LeetCode上的原题,请参见我之前的博客Factorial Trailing Zeroes.…
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 主要是思考清楚计算过程: 将一个数进行因式分解,含有几个5就可以得出几个0(与偶数相乘). 代码很简单. public class Solution { public int trailingZeroes(int n) { int result =…