不服气,川大数学博士吐槽华为招聘

数学博士吐槽华为招聘

今天刷到一篇帖子:

文中来自川大的数学博士吐槽了华为对数学博士的招聘。

作者强调自己是川大的本硕博(算子分析方向),有论文,也拿过国家一等奖。

但自己投的华为简历,却石沉大海,了无音讯。

还直言道:自己在数学系待了 10 年,没有任何一个数学博士能够满足华为招聘三条要求中的两条,如果数学博士干的是华为招聘上的事情,毕业都难。

这事儿,怎么说呢,从不同角度,会有不同的理解。

首先,在企业招聘中,学历往往是起点门槛要求,而非唯一要求。

因此肯定不是说满足数学博士要求,就必然入面试,这一点和「本科/硕士」一样。

其次,企业招聘中,往往是「应用类」人才占比要比「科研类」人才占比更高。

因此在学历(数学博士)要求上,往往还会有企业所期望的技能要求,例如文中说的「熟练使用计算机编程语言」,也算是常规操作。

至于原帖作者说的,因为「华为招聘中有很多不是数学博士专业领域知识要求」,就得出「华为觉得不到这个水平就不算是博士」的结论,多少有点偏激了。

...

回归主线。

来一道不是数学博士也能做出来的算法题。

这道题曾经还是华为的校招机试原题。

题目描述

平台:LeetCode

题号:172

给定一个整数 <math xmlns="http://www.w3.org/1998/Math/MathML"> n n </math>n ,返回 <math xmlns="http://www.w3.org/1998/Math/MathML"> n ! n! </math>n! 结果中尾随零的数量。

提示 n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1

示例 1:

ini 复制代码
输入:n = 3

输出:0

解释:3! = 6 ,不含尾随 0

示例 2:

ini 复制代码
输入:n = 5

输出:1

解释:5! = 120 ,有一个尾随 0

提示:

  • <math xmlns="http://www.w3.org/1998/Math/MathML"> 0 < = n < = 1 0 4 0 <= n <= 10^4 </math>0<=n<=104

进阶:你可以设计并实现对数时间复杂度的算法来解决此问题吗?

数学

对于任意一个 <math xmlns="http://www.w3.org/1998/Math/MathML"> n ! n! </math>n! 而言,其尾随零的个数取决于展开式中 <math xmlns="http://www.w3.org/1998/Math/MathML"> 10 10 </math>10 的个数,而 <math xmlns="http://www.w3.org/1998/Math/MathML"> 10 10 </math>10 可由质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 ∗ 5 2 * 5 </math>2∗5 而来,因此 <math xmlns="http://www.w3.org/1998/Math/MathML"> n ! n! </math>n! 的尾随零个数为展开式中各项分解质因数后 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 2 </math>2 的数量和 <math xmlns="http://www.w3.org/1998/Math/MathML"> 5 5 </math>5 的数量中的较小值。

即问题转换为对 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 1 , n ] [1, n] </math>[1,n] 中的各项进行分解质因数,能够分解出来的 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 2 </math>2 的个数和 <math xmlns="http://www.w3.org/1998/Math/MathML"> 5 5 </math>5 的个数分别为多少。

为了更具一般性,我们分析对 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 1 , n ] [1, n] </math>[1,n] 中各数进行分解质因数,能够分解出质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的个数为多少。根据每个数能够分解出 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的个数进行分情况讨论:

  • 能够分解出至少一个 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的倍数,在 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 1 , n ] [1, n] </math>[1,n] 范围内此类数的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> c 1 = ⌊ n p ⌋ c_1 = \left \lfloor \frac{n}{p} \right \rfloor </math>c1=⌊pn⌋
  • 能够分解出至少两个 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> p 2 p^2 </math>p2 的倍数,在 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 1 , n ] [1, n] </math>[1,n] 范围内此类数的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> c 2 = ⌊ n p 2 ⌋ c_2 = \left \lfloor \frac{n}{p^2} \right \rfloor </math>c2=⌊p2n⌋
  • ...
  • 能够分解出至少 <math xmlns="http://www.w3.org/1998/Math/MathML"> k k </math>k 个 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> p k p^k </math>pk 的倍数,在 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 1 , n ] [1, n] </math>[1,n] 范围内此类数的个数为 <math xmlns="http://www.w3.org/1998/Math/MathML"> c k = ⌊ n p k ⌋ c_k = \left \lfloor \frac{n}{p^k} \right \rfloor </math>ck=⌊pkn⌋

我们定义一个合法的 <math xmlns="http://www.w3.org/1998/Math/MathML"> k k </math>k 需要满足 <math xmlns="http://www.w3.org/1998/Math/MathML"> p k ⩽ n p^k \leqslant n </math>pk⩽n,上述的每一类数均是前一类数的「子集」(一个数如果是 <math xmlns="http://www.w3.org/1998/Math/MathML"> p k p^k </math>pk 的倍数,必然是 <math xmlns="http://www.w3.org/1998/Math/MathML"> p k − 1 p^{k-1} </math>pk−1 的倍数),因此如果一个数是 <math xmlns="http://www.w3.org/1998/Math/MathML"> p k p^k </math>pk 的倍数,其出现在的集合数量为 <math xmlns="http://www.w3.org/1998/Math/MathML"> k k </math>k,与其最终贡献的 <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 的数量相等。

回到本题, <math xmlns="http://www.w3.org/1998/Math/MathML"> n ! n! </math>n! 中质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 2 </math>2 的数量为 :
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∑ i = 1 k 1 ⌊ n 2 i ⌋ = ⌊ n 2 ⌋ + ⌊ n 2 2 ⌋ + . . . + ⌊ n 2 k 1 ⌋ \sum_{i = 1}^{k_1}\left \lfloor \frac{n}{2^i} \right \rfloor = \left \lfloor \frac{n}{2} \right \rfloor + \left \lfloor \frac{n}{2^2} \right \rfloor + ... + \left \lfloor \frac{n}{2^{k_1}} \right \rfloor </math>i=1∑k1⌊2in⌋=⌊2n⌋+⌊22n⌋+...+⌊2k1n⌋

<math xmlns="http://www.w3.org/1998/Math/MathML"> n ! n! </math>n! 中质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 5 5 </math>5 的数量为 :
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∑ i = 1 k 2 ⌊ n 5 i ⌋ = ⌊ n 5 ⌋ + ⌊ n 5 2 ⌋ + . . . + ⌊ n 5 k 2 ⌋ \sum_{i = 1}^{k_2}\left \lfloor \frac{n}{5^i} \right \rfloor = \left \lfloor \frac{n}{5} \right \rfloor + \left \lfloor \frac{n}{5^2} \right \rfloor + ... + \left \lfloor \frac{n}{5^{k_2}} \right \rfloor </math>i=1∑k2⌊5in⌋=⌊5n⌋+⌊52n⌋+...+⌊5k2n⌋

由 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 < 5 2 < 5 </math>2<5,可知 <math xmlns="http://www.w3.org/1998/Math/MathML"> k 2 ⩽ k 1 k_2 \leqslant k_1 </math>k2⩽k1,同时 <math xmlns="http://www.w3.org/1998/Math/MathML"> i i </math>i 相同的每一项满足 <math xmlns="http://www.w3.org/1998/Math/MathML"> ⌊ n 5 i ⌋ ⩽ ⌊ n 2 i ⌋ \left \lfloor \frac{n}{5^i} \right \rfloor \leqslant \left \lfloor \frac{n}{2^i} \right \rfloor </math>⌊5in⌋⩽⌊2in⌋,可知最终 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∑ i = 1 k 2 ⌊ n 5 i ⌋ ⩽ ∑ i = 1 k 1 ⌊ n 2 i ⌋ \sum_{i = 1}^{k_2}\left \lfloor \frac{n}{5^i} \right \rfloor \leqslant \sum_{i = 1}^{k_1}\left \lfloor \frac{n}{2^i} \right \rfloor </math>∑i=1k2⌊5in⌋⩽∑i=1k1⌊2in⌋,即质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 5 5 </math>5 的个数必然不会超过质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 2 2 </math>2 的个数。我们只需要统计质因数 <math xmlns="http://www.w3.org/1998/Math/MathML"> 5 5 </math>5 的个数即可。

Java 代码:

Java 复制代码
class Solution {
    public int trailingZeroes(int n) {
        return n == 0 ? 0 : n / 5 + trailingZeroes(n / 5);
    }
}

Python 代码:

Python 复制代码
class Solution:
    def trailingZeroes(self, n: int) -> int:
        return n // 5 + self.trailingZeroes(n // 5) if n else 0
  • 时间复杂度: <math xmlns="http://www.w3.org/1998/Math/MathML"> O ( log ⁡ n ) O(\log{n}) </math>O(logn)
  • 空间复杂度:忽略递归带来的额外空间开销,复杂度为 <math xmlns="http://www.w3.org/1998/Math/MathML"> O ( 1 ) O(1) </math>O(1)

我是宫水三叶,每天都会分享算法题解,并和大家聊聊近期的所见所闻。

欢迎关注,明天见。

更多更全更热门的「笔试/面试」相关资料可访问排版精美的 合集新基地 🎉🎉

相关推荐
华农第一蒟蒻10 分钟前
Java中JWT(JSON Web Token)的运用
java·前端·spring boot·json·token
积水成江11 分钟前
关于Generator,async 和 await的介绍
前端·javascript·vue.js
___Dream13 分钟前
【黑马软件测试三】web功能测试、抓包
前端·功能测试
金灰13 分钟前
CSS3练习--电商web
前端·css·css3
人生の三重奏16 分钟前
前端——js补充
开发语言·前端·javascript
计算机学姐24 分钟前
基于SpringBoot+Vue的高校运动会管理系统
java·vue.js·spring boot·后端·mysql·intellij-idea·mybatis
Tandy12356_28 分钟前
js逆向——webpack实战案例(一)
前端·javascript·安全·webpack
TonyH200230 分钟前
webpack 4 的 30 个步骤构建 react 开发环境
前端·css·react.js·webpack·postcss·打包
你会发光哎u34 分钟前
Webpack模式-Resolve-本地服务器
服务器·前端·webpack
王小二(海阔天空)35 分钟前
个人文章合集 - 前端相关
前端·css·vue·jquery