亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用比奈公式在 python 中獲取較大斐波那契數的準確值

使用比奈公式在 python 中獲取較大斐波那契數的準確值

aluckdog 2021-10-26 16:08:51
我正在學習 itertools 并試圖測試在 python 中實現的 Binet 公式的準確性。使用 itertools 的原因是我假設這將需要大量迭代,并且只有在大量迭代后才會出現差異。from math import sqrtimport itertools#fibonacci function 2def fib1():    n = -1    while True:        n += 1        yield int(((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5)))#fibonacci function 1def fib2():    a,b = 0,1    while True:        yield a        a, b = b, a + br=itertools.dropwhile(lambda x: x[0]==x[1],itertools.zip_longest(fib1(),fib2()))for item in itertools.islice(r,0,1):    print(item)輸出:(498454011879265, 498454011879264)在使用之前int()我使用round()過fib1(),結果是(308061521170130, 308061521170129)可以做些什么來提高我的比奈公式實現的準確性?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號