`

A Google's Interview Question - GLAT #20 series 2

阅读更多
Now, we can deduct the recursion formula on digits

Lemma 4

Let

 n = a_k * 10^k  + a_(k-1) * 10^(k-1) + ....... + a_1 * 10 + a_0

denote the base 10 expansion, then

when a_k = 1

(A)   f(n) = f(n - 10^k) + (n - 10^k) + f(10^k) = f(n - 10^k) + (n - 10^k) + k * 10^(k-1) + 1

and when a_k > 1

(B)   f(n) = f(n - a_k * 10^k) + f(a_k * 10^k) = f(n - a_k * 10^k) + a_k * k * 10^(k-1) + 10^k


In A, since a_k = 1, n - 10^k is really the number without the leading digit. So the first term is the 1's above 10^k without leading 1's. The second term is the leading 1's above 10^k. The 3rd term is the 1's from the numbers up to 10^k.

In B, the first term is the 1's above a_k * 10^k and the second term is the 1's below a_k * 10^k.

Further more, from (A)

f(n)  > (n - 10^k) + k  * 10^(k-1) (ignore the f(n-10^k) and 1 terms)
        = n + (k - 10) * 10 ^(k-1)

from (B)

f(n) > a_k  *  k  *  10^(k-1) + 10^k (ignore the first term)
     > a_k * k * 10^(k-1) + n - a_k * 10 ^k
     = n + a_k * (k - 10) * 10^(k-1)

so in either case, when k >= 10, f(n) > n. This means the upper bound for n such that f(n) = n is 10^10.

From here on, if we want to find all integers n such that f(n) = n, then looping through 1 to 10^10 is still a long task, could take several hours. So we still need to dig some information from the function f(n) to narrow down our search.

Lemma 5.

All positive integers are divided by the fixed points of f(n) such that in each interval, we either have f(x) > x or f(x) < x throughout the entire interval.

Obviously, f(n) is a non decreasing function, i.e., if x > y, then f(x) >= f(y). So for any given positive integer n, if f(n) > n, then f(f(n)) >= f(n) > n. This means n, f(n), f(f(n)), ...... form an increasing series. Furthermore, there can't exist any fixed point m between any two distinct adjacent points in this series such that f(m) = m. Otherwise, if exists y such that n < m < f(n), then act f on them would get f(n) <= f(m) <= f(f(m)). This leads f(n) <= f(m) = m, contradicts to where we start m < f(n) <= m. This means the entire series must lie between fixed points.

If there are two points x and y in such an internal(i.e., no more fixed points besides the end points), such that f(x) > x, and f(y) < y. Then we will show there must be a fixed point between x and y.
If x < y, then this means x-series and y-series are merging in finite steps. Since all y-series are upper bounder, x-series has to stop before reaching y-series, there must be a number x_0 in x-series such that x_0 = f(x_0).
if x > y, then this means they are diverging away to two endpoints. If we keep bisect x and y, we end up the case where there is an integer z such that f(z) <= z < z + 1 <= f(z + 1). If both z and z+1 are not fixed points, then f inverse on z would be >= z+1.
if z_0 is one of the inverse, then
z < z + 1 < z_0 and f(z_0) = z.
Then acting f on this ends up with
f(z) <= f(z + 1) <= f(z_0) = z
This contradicts with the fact f(z + 1) >= z + 1 > z.
So there must be at least a fixed point in the middle.

Lemma 5 is the beauty of this function.
分享到:
评论

相关推荐

    Google 招聘的21道题目

    根据给定的信息,我们可以推断出这是一篇关于Google招聘测试的文章,具体是关于Google实验室能力倾向测试(GLAT)的介绍与解析。虽然提供的内容片段并不完整,但基于现有信息,我们可以对提及的每一道题目进行详细...

    IT行业笔试汇总(C,设计模式)

    - **背景介绍**:2004年10月,Google在几本专业杂志上发布了名为“Google实验室能力倾向测试”(GLAT)的一份特殊招聘试题。这份试题在全球范围内引起了广泛的关注,不仅因为它出自全球领先的科技公司之一Google,还...

    依巴谷输入星表集第2版数据文档.pdf

    依巴谷输入星表集第2版数据文档 依巴谷输入星表集(第2版)是欧洲空间局(ESA)为依巴谷天体测量卫星工作使用的输入星表,该卫星在轨运行四年,从1989年11月到1993年3月间返回了高质量的科学数据。该数据集于1993年...

    opengl库文件glut头文件和库

    下载后解开压缩包,里面有五个文件:glut.h,glut.lib,glut32.lib,glut.dll,glut32.dll。 然后把.h文件放到VC的include路径下的GL文件夹下,VC++6.0版本对应的文件夹是安装路径下VC98\Include\GL。...

    idl代码与Matlab-NCAR-GLOW:CMake,Meson,Matlab,GLOW的Python增补。NCAR只想发布基本代码

    idl代码与Matlab 辉光 Global airglOW模型,可以从Fortran 2003编译器中独立且轻松地进行访问。 可选提供脚本语言,包括: Python≥3.6 Matlab的 GNU八度≥4.2 IDL ...glat , glon , Q , Echar , Nb

    利用日期,经纬度求日落时间的C语言程序文件.pdf

    2. **纬度和经度处理**:`input_glat`和`input_glong`函数分别用于获取用户输入的纬度和经度,以度分秒的形式。纬度范围限制在0°至60°之间,经度可以是负值,表示西经。 3. **时间计算**:`t_century`函数将从...

    pcloud2grid:此函数将点云转换为 MATLAB 样式的网格。-matlab开发

    接收 xyz 格式的点云,然后将其转换为具有纬度向量、经度向量、glat/glon 网格(使用 meshgrid)和 az(高度)矩阵的 MATLAB 样式的网格。 然后将这些保存到指定的输出 .mat 文件中。

    MilkMan:银河计划数据缩减工具

    它的构建允许任何人检查志愿者为数据库中或任何 GLON、GLAT 位置的任何主题(图像)创建的分类。 对于每个图像,您都可以看到原始志愿者绘图、聚类结果和该地区 SIMBAD 上的对象(这一点还没有完全完成)。 例如...

Global site tag (gtag.js) - Google Analytics