黄金比1000桁

特に意味も芸も無く黄金比を1000桁

# coding: utf-8
# goldenratio.py
def fib():
    a = b = 1
    while True:
        yield a
        a,b = b,a+b

def iteration(p):
    factor = 10**p
    it = fib()
    x = it.next()
    y = it.next()
    cur = x
    pre = 100 ##とくに意味なし
    while abs(cur - pre) > 1:
        #print cur, pre, cur-pre
        pre = cur
        cur = factor*y/x
        x = y
        y = it.next()
    return cur


import sys
s = int(sys.argv[1])
print iteration(s)

実行

$ python goldenratio.py 1010
161803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807538689175212663386222353693179318006076672635443338908659593958290563832266131992829026788067520876689250171169620703222104321626954862629631361443814975870122034080588795445474924618569536486444924104432077134494704956584678850987433944221254487706647809158846074998871240076521705751797883416625624940758906970400028121042762177111777805315317141011704666599146697987317613560067087480710131795236894275219484353056783002287856997829778347845878228911097625003026961561700250464338243776486102838312683303724292675263116533924731671112115881863851331620384005222165791286675294654906811317159934323597349498509040947621322298101726107059611645629909816290555208524790352406020172799747175342777592778625619432082750513121815628551222480939471234145170223735805772786160086883829523045926478780178899219902707769038953219681986151437803149974110692608867429622675756052317277752035361393621076738937

整形

$ python goldenratio.py 1010 | python -c "import sys,re; lst = re.findall(r'(\d{10,10}|\d+)', sys.stdi
n.read()); print '\n'.join(['%4d | ' % (i*50+1) + ' '.join(lst[i*5:i*5+5]) for i in range(len(lst)/5)]); print '
     ' + ' '.join(lst[len(lst)/5*5:len(lst)/5*5+5])"
   1 | 1618033988 7498948482 0458683436 5638117720 3091798057
  51 | 6286213544 8622705260 4628189024 4970720720 4189391137
 101 | 4847540880 7538689175 2126633862 2235369317 9318006076
 151 | 6726354433 3890865959 3958290563 8322661319 9282902678
 201 | 8067520876 6892501711 6962070322 2104321626 9548626296
 251 | 3136144381 4975870122 0340805887 9544547492 4618569536
 301 | 4864449241 0443207713 4494704956 5846788509 8743394422
 351 | 1254487706 6478091588 4607499887 1240076521 7057517978
 401 | 8341662562 4940758906 9704000281 2104276217 7111777805
 451 | 3153171410 1170466659 9146697987 3176135600 6708748071
 501 | 0131795236 8942752194 8435305678 3002287856 9978297783
 551 | 4784587822 8911097625 0030269615 6170025046 4338243776
 601 | 4861028383 1268330372 4292675263 1165339247 3167111211
 651 | 5881863851 3316203840 0522216579 1286675294 6549068113
 701 | 1715993432 3597349498 5090409476 2132229810 1726107059
 751 | 6116456299 0981629055 5208524790 3524060201 7279974717
 801 | 5342777592 7786256194 3208275051 3121815628 5512224809
 851 | 3947123414 5170223735 8057727861 6008688382 9523045926
 901 | 4787801788 9921990270 7769038953 2196819861 5143780314
 951 | 9974110692 6088674296 2267575605 2317277752 0353613936
       2107673893 7

簡単に多倍長計算できるPythonは偉い!