fib = {}
f = [1, 1]
fib[1] = True
while f[-1] < 1e10: # 不断的计算,然后加在尾部,最后比对“in”
    f.append(f[-1]+f[-2])
    fib[f[-1]] = True
T = input()
for i in xrange(T):
    N = input()
    if N in fib:
        print 'IsFibo'
    else:
        print 'IsNotFibo'

Link:

  https://www.hackerrank.com/challenges/is-fibo

学习:

  一次性计算出来,然后比对in

 posted on 2015-05-18 09:23  sangocare  阅读(174)  评论(0编辑  收藏  举报