Additive Sequence

南笙酒味 提交于 2019-12-11 05:59:48

问题


additive sequence. 3,3,6,9,15.... is called an additive sequence where the first two numbers must be the same..3+3=6,3+6=9 and so on. Also a number can be split into one of more digits to from the additive sequence. For eg: 12,122,436... In that sequence,12+12=24....12+24=36. The question is given the starting and ending numbers,find all the possible terms in the additive sequence. I get it that one sequence can be found pretty easily.But I have no clue how to take the bigger numbers like 122,436 etc into consideration.


回答1:


For the sake of simplicity I'll say that an additive sequence is strict if no numbers are split. Strict additive sequences have the following form: n*1, n*1, n*2, n*3, n*5, ..., n*Fk, where Fk is the k-th Fibonacci number. Hence, for strict sequences you need to divide the last element by the first one and check whether the result is a Fibonacci number. If yes, the sequence can be easily reconstructed. If no, no such sequence exists.

Let us now consider non-strict additive sequences and let A1...An be the first number. First of all, we try to find a strict additive sequence as explained above. If this attempt fails and an additive sequence exists, either A1...An or the last number should represent MORE then one "actual" number.

If A1...An represents more than one "actual" number, then there exists k <= n such that A_1+p = A_k+p for all 0 <= p <= min(n-k,k) (since the second number should be equal to the first one). If no such k can be found, there is no additive sequence. If such k can be found, try all numbers of the form A1...A_k-1 * F(m), where F(m) is the m'th Fibonacci number as long as this product is less or equal than the last number, and try to fit the sequence. If there is more than one such k (111) try all possibilities.

If the last number represents multiple numbers and A1...An does not, try all numbers of the form A1...A_n * F(m) in the same way as above.



来源:https://stackoverflow.com/questions/7911875/additive-sequence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!