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

数位函数递归
本文探讨了一种关于数字中1的数量的递归公式,并通过分析得出对于任何给定的正整数n,若f(n) > n,则形成递增序列且在序列中不存在f(m) = m的情况。进一步地,文章提出并证明了在没有其它固定点的情况下,区间内f(x)相对于x的变化趋势保持一致。
部署运行你感兴趣的模型镜像
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.

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

提供了一个基于51单片机的RFID门禁系统的完整资源文件,包括PCB图、原理图、论文以及源程序。该系统设计由单片机、RFID-RC522频射卡模块、LCD显示、灯控电路、蜂鸣器报警电路、存储模块和按键组成。系统支持通过密码和刷卡两种方式进行门禁控制,灯亮表示开门成功,蜂鸣器响表示开门失败。 资源内容 PCB图:包含系统的PCB设计图,方便用户进行硬件电路的制作和调试。 原理图:详细展示了系统的电路连接和模块布局,帮助用户理解系统的工作原理。 论文:提供了系统的详细设计思路、实现方法以及测试结果,适合学习和研究使用。 源程序:包含系统的全部源代码,用户可以根据需要进行修改和优化。 系统功能 刷卡开门:用户可以通过刷RFID卡进行门禁控制,系统会自动识别卡片并判断是否允许开门。 密码开门:用户可以通过输入预设密码进行门禁控制,系统会验证密码的正确性。 状态显示:系统通过LCD显示屏显示当前状态,如刷卡成功、密码错误等。 灯光提示:灯亮表示开门成功,灯灭表示开门失败或未操作。 蜂鸣器报警:当刷卡或密码输入错误时,蜂鸣器会发出报警声,提示用户操作失败。 适用人群 电子工程、自动化等相关专业的学生和研究人员。 对单片机和RFID技术感兴趣的爱好者。 需要开发类似门禁系统的工程师和开发者。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值