74th LeetCode Weekly Contest Preimage Size of Factorial Zeroes Function
Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.)
For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has 2 zeroes at the end. Given K, find how many non-negative integers x have the property that f(x) = K.
Example 1:
Input: K = 0
Output: 5
Explanation: 0!, 1!, 2!, 3!, and 4! end with K = 0 zeroes. Example 2:
Input: K = 5
Output: 0
Explanation: There is no x such that x! ends in K = 5 zeroes.
Note:
Kwill be an integer in the range[0, 10^9].
或许都知道N!0的个数是怎么算的,但倒过来呢,但打表发现...答案就0和5两种可能
我猜是因为规律是除以5造成的吧...
然后我们二分一下K...
class Solution
{
public:
int numOfZero(int n){
int num = , i;
for(i=; i<=n; i*=)
{
num += n/i;
}
return num;
}
map<int,int>Mp;
int preimageSizeFZF(int K){
int l=K,r=K*+;
while(l<r){
int mid=l+(r-l)/;
if(numOfZero(mid)==K){
return ;
}else if(numOfZero(mid)<K){
l=mid+;
}else{
r=mid;
}
}
return ;
}
};
74th LeetCode Weekly Contest Preimage Size of Factorial Zeroes Function的更多相关文章
- 793. Preimage Size of Factorial Zeroes Function
Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by con ...
- [LeetCode] Preimage Size of Factorial Zeroes Function 阶乘零的原像个数函数
Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by con ...
- 【leetcode】Preimage Size of Factorial Zeroes Function
题目如下: 解题思路:<编程之美>中有一个章节是不要被阶乘吓倒,里面讲述了“问题一:给定一个整数N,那么N的阶乘末尾有多少个0呢?例如N = 10, N! = 362800,N! 的末尾有 ...
- [Swift]LeetCode793. 阶乘函数后K个零 | Preimage Size of Factorial Zeroes Function
Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by con ...
- 74th LeetCode Weekly Contest Number of Subarrays with Bounded Maximum
We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...
- 74th LeetCode Weekly Contest Valid Number of Matching Subsequences
Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of ...
- 74th LeetCode Weekly Contest Valid Tic-Tac-Toe State
A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
随机推荐
- OpenCV4Android 不需要安装OpenCVManager,就可以运行的方法
http://blog.csdn.net/yanzi1225627/article/details/27863615 OpenCV4Android释疑: 透析Android以JNI调OpenCV的三种 ...
- 第二天:tomcat体系结构和第一个Servlet
1. 打war包 2. Tomcat体系再说明: 问题:如何去配置默认主机??? 3.tomcat和servlet在网络中的位置 4. servlet快速入门案例 1).开发s ...
- Windows系统上release版本程序bug跟踪解决方案(1)-日志记录
使用场景: Win32程序在release模式下编译完成,发送给最终用户使用时,我们的程序有时候也会出现崩溃的情况,这个时候如果能快速定位崩溃原因或提供一些程序崩溃时的状态信息,对我们解决问题将会带来 ...
- new与delete,malloc与free
1.new_delete与malloc_free ❶malloc/free: malloc原型: void *malloc(long NumBytes) 该函数分配了NumBytes个字节,并返回了指 ...
- NULL、0、nullptr
C的NULL 在C语言中,我们使用NULL表示空指针,也就是我们可以写如下代码: int *i = NULL;foo_t *f = NULL; 实际上在C语言中,NULL通常被定义为如下: #defi ...
- Angular问题01 创建组件时报错、HammerJS找不到
1 利用ng创建组件时出现错误 1.1 ng g c test/testHome 1.2 问题描述 当angular应用中有多个module.ts文件时,创建组件时会出现冲突,因为有多个module. ...
- Linux 大页面使用与实现简介(转)
引言 随着计算需求规模的不断增大,应用程序对内存的需求也越来越大.为了实现虚拟内存管理机制,操作系统对内存实行分页管理.自内存“分页机制”提出之始,内存页面的默认大小便被设置为 4096 字节(4KB ...
- 算法Sedgewick第四版-第1章基础-025-用队列实现unix下的Directory命令
package algorithms.util; /************************************************************************** ...
- HBase 协处理器统计行数
环境:cdh5.1.0 启用协处理器方法1. 启用协处理器 Aggregation(Enable Coprocessor Aggregation) 我们有两个方法:1.启动全局aggregation, ...
- Luogu 3457 [POI2007]POW-The Flood
感觉自己什么题都写不动了. 又是一个神贪心:把所有城市中的点按照高度从小到大排序之后拿出来逐个计算,枚举其他高度小于它的点向四周扩展,如果这个点不能被之前放过的抽水机覆盖,那么把答案加一,并在这个点放 ...