Self-describing Sequence

2020年1月17日 1216点热度 0人点赞 0条评论

Self-describing Sequence

时间: 1ms        内存:64M

描述:

Self-describing Sequence

Solomon Golomb's self-describing sequence {f (1), f (2), f (3),...} is the only non-decreasing sequence of positive integers with the property that it contains exactly f (k) occurrences of k for each k. A few moment's thought reveals that the sequence must begin as follows:

n 1 2 3 4 5 6 7 8 9 10 11 12
f (n) 1 2 2 3 3 4 4 4 5 5 5 6

In this problem you are expected to write a program that calculates the value of f (n) given the value of n.

输入:

The input may contain multiple test cases. Each test case occupies a separate line and contains an integer n ( 1<=n<=2, 000, 000, 000). The input terminates with a test case containing a value 0 for n and this case must not be processed.

输出:

For each test case in the input, output the value of f (n) on a separate line

示例输入:

100
9999
123456
1000000000
0

示例输出:

21
356
1684
438744

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论