First appearance in Stern's Diatomic Sequence
问题 You get an integer n and you need to find the index of its first appearance in Stern's Diatomic Sequence. The sequence is defined like this: a[0] = 0 a[1] = 1 a[2*i] = a[i] a[2*i+1] = a[i] + a[i+1] See MathWorld. Because n can be up to 400000, it's not a good idea to brute-force it, especially since the time limit is 4000 ms. The sequence is pretty odd: first occurrence of 8 is 21, but first occurrence of 6 is 33. Any ideas how to solve this? Maybe this might help: OEIS 回答1: We can easily