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. 跨域Ajax原理以及浏览器同源策略

  2. oracle DML-(insert、select、update、delete)

    一.插入记录INSERT INTO table_name (column1,column2,...) values ( value1,value2, ...); 示例:insert into emp ...

  3. transient关键字的理解

    谈到这个transient这个关键字,我们应该会立马想到序列化这个过程:什么是序列化?什么又是反序列化呢?序列化就是将对象转化内成二进制,而反序列化就是就二进制文件转换成对象的过程.一旦变量使用了tr ...

  4. gearman 并发的执行多个任务

    Examples: Multi-Query In this example we know that we need to fetch several result sets from a datab ...

  5. Git 之 协同开发

    GitHub中多人协同开发和单人开发还是有点差别,协同开发一般有两种方式: 合作者,将其他用户添加到仓库合作者中之后,该用户就具有向当前仓库提交代码. 组织,创建一个组织,然后再该组织下可以创建多个项 ...

  6. Java基础-集合框架的学习大纲

    1.List 和 Set 的区别 2.HashSet 是如何保证不重复的 3.HashMap 是线程安全的吗,为什么不是线程安全的(最好画图说明多线程环境下不安全)? 4.HashMap 的扩容过程 ...

  7. 关于setVisibility的几个常量

    在xml文件中,view控件一般都会有android:visibility这个属性 android:visibility:gone|cisible|invisible 在代码中,可以通过方法setVi ...

  8. Iterator主要有三个方法:hasNext()、next()、remove()详解

    一.Iterator的API 关于Iterator主要有三个方法:hasNext().next().remove() hasNext:没有指针下移操作,只是判断是否存在下一个元素 next:指针下移, ...

  9. [译]javascript中的条件语句

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  10. sizeof的用法与字节对齐

    一.sizeof是什么? sizeof是一种预编译处理,不是函数,不是一元表达式.也即,作用阶段在编译期. 二.功能是什么? sizeof返回变量或类型的字节数. 三.调用方式 sizeof(obje ...