For simplicity, I will say that the additive sequence is strict if no numbers are separated. Strict additive sequences have the following form: n * 1, n * 1, n * 2, n * 3, n * 5, ..., n * Fk, where Fk is the kth Fibonacci number. Therefore, for strict sequences, you need to divide the last element into the first and check whether the result is a Fibonacci number. If so, the sequence can be easily restored. If not, such a sequence does not exist.
We now consider non-strict additive sequences and let A1 ... An be the first number. First of all, we are trying to find a strict additive sequence, as described above. If this attempt fails and there is an additive sequence, either A1 ... An, or the last number must represent MORE, and 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 (nk, k) (since the second number must be equal to the first). If such k is not found, there will be 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 if this product is less than or equal to the last number and try to establish the sequence. If there is more than one such k (111), try all the possibilities.
If the last number is several numbers and A1 ... An does not, try all numbers of the form A1 ... A_n * F (m) in the same way as above.
source share