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:

  • K will 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的更多相关文章

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

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

  3. 【leetcode】Preimage Size of Factorial Zeroes Function

    题目如下: 解题思路:<编程之美>中有一个章节是不要被阶乘吓倒,里面讲述了“问题一:给定一个整数N,那么N的阶乘末尾有多少个0呢?例如N = 10, N! = 362800,N! 的末尾有 ...

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

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

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

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

  8. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  9. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

随机推荐

  1. 免安装Oracle客户端使用PL/SQL连接Oracle

    只需要在Oracle下载一个叫Instant Client Package的软件就可以了,这个软件不需要安装,只要解压就可以用了,很方便,就算重装了系统还是可以用的. 下载地址:http://www. ...

  2. MyBatis总结八:缓存介绍(一级缓存,二级缓存)

    简介 为数据库的查询进行缓存,是减少数据库压力的主要途径.分为一级缓存和二级缓存. 一级缓存:session级别缓存,作用于当前会话. 二级缓存:SessionFactory级别缓存,作用于整个Ses ...

  3. sh 脚本重启/更新 Tomcat 项目

    一.项目文件为一个 jar 包,无须解压 重启 Tomcat 项目 #!/bin/bash echo "kill hot-jdt" kill -9 `ps -ef|grep hot ...

  4. C++ 私有构造函数的作用

    很多情况下要求当前的程序中只有一个object.例如一个程序只有一个和数据库的连接,只有一个鼠标的object.通常我们都将构造函数的声明置于public区段,假如我们将 其放入private区段中会 ...

  5. js 操作属性,操作内容,

    disable=“disable” 让按钮变得不可选 先建一个按钮,让class = ’btn‘ 然后, 添加,修改属性 document.getElementsByClassName('btn')[ ...

  6. ruby 类方法、实例方法、类变量

    ###################### #类变量 ###################### class Cloud @@count=0 def initialize(user,passwor ...

  7. Linux uname命令

    一.简介 uname 命令将正在使用的操作系统名写到标准输出中. 二.语法 -a 显示 -m. -n. -r. -s 和 -v 标志指定的所有信息.不能与 -x 或 -SName 标志连用.如果 -x ...

  8. python列表--查找集合中重复元素的个数

    方法一: >>> mylist = [1,2,2,2,2,3,3,3,4,4,4,4] >>> myset = set(mylist) >>> f ...

  9. Git 之 初使用

    什么是Git? Git 是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发.Git ...

  10. 原型模式--其实就是考察clone

    http://blog.csdn.net/zhengzhb/article/details/7393528