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