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. C程序设计语言(K&R) 笔记2

    (1) #include <stdio.h> main(){ int c; while((c = getchar()) != EOF){ putchar(c); } } 注意,因为 != ...

  2. 给Activity切换过程添加动画效果

    首先,在资源文件中定义一些动画效果 例如: <scale android:duration="@android:integer/config_mediumAnimTime" ...

  3. koa2 原生链接mysql

    1.安装mysql $ npm install mysql 2.代码示例: const mysql = require("mysql"); // mysql.Promise = g ...

  4. cocos2d-js 浏览器与JSB内存管理机制的不同

    写这边文章的主要目的是为了理解使用cocos3d-js开发app时,浏览器调试与真机情况不一致的原因 一.浏览器中内存管理机制 HTML5版本运行时,整个游戏只存在JS脚本与一些必要的资源文件,这时候 ...

  5. String/StringBuilder 类 用对象数组实现登录注册功能

    一.需求说明:实现用户注册.登陆功能: 程序中使用一个长度为3的对象数组,存储用户的登录名和密码: 例如如下格式: 登录名    密码      生日           爱好 zhangsan 11 ...

  6. g2o20160424 CMakeLists.txt

    LIB_PREFIX: 设置生成库的前缀 SET(LIB_PREFIX g2o_) # The library prefix SET(LIB_PREFIX g2o_) 变量的默认配置 # defaul ...

  7. spark 1.5的hivecontext的问题

    spark升级到1.5,里面的hive版本升级到1.2.1版本,我写了如下的代码 object SQLApp extends App{ val sparkconf = new SparkConf(). ...

  8. arp绑定

    Windows xp 在CMD中执行 arp -s ip mac 例如 arp -s 192.168.2.101 40-5f-c2-c1-97-fb Windwos 7 在 Windows 7/Vis ...

  9. RobotFramework教程使用笔记——robotframwork中文乱码显示问题

    转自:https://www.cnblogs.com/dreamyu/p/6878795.html 接口.数据库返回信息有中文的时候会显示unicode的样式,前面带个U这样的显示,如果我们想让它正常 ...

  10. 【转】C#对XML文件的各种操作实现方法

    [转]C#对XML文件的各种操作实现方法 原文:http://www.jb51.net/article/35568.htm XML:Extensible Markup Language(可扩展标记语言 ...