Test if a number is fibonacci

后端 未结 20 947
深忆病人
深忆病人 2020-11-30 17:58

I know how to make the list of the Fibonacci numbers, but i don\'t know how can i test if a given number belongs to the fibonacci list - one way that comes in mind is genera

20条回答
  •  盖世英雄少女心
    2020-11-30 18:12

    How big are the numbers you're dealing with?

    Could a lookup table work for you? (a precomputed list of numbers you can search in)

    There's also a closed-form expression that I guess you could invert to get at the answer analytically (though I'm no mathematician, so I can't promise this suggestion makes sense)

提交回复
热议问题