unclecat.net - 不胖的猫叔的阴暗角落

Example domain paragraphs

Menu Problem 2-Even Fibonacci numbers 2017-08-14 2017-08-14 ~ yjxie ~ Leave a comment There are tons of algorithms for generating the Fibonacci numbers, such as the recursive way which is quite elegant. However, for this problem only, we don’t need to generate the whole sequence.

Suppose we have already know what and are, it’s easy to calculate . Then we check whether is even or not. If it’s even, we sum the number to the final result. Next we update and , and move to the next item in Fibonacci sequence.

The virtue of this method is to (supposedly) reduce the memory usage. Although there are only 34 Fibonacci numbers under 4 million, and I don’t see a particular reason for avoiding generating all these numbers.