48 lines
828 B
Python
48 lines
828 B
Python
unit = 1000000000
|
|
bigunit = 1.0e+100
|
|
|
|
def musq(a, b):
|
|
bi = []
|
|
while b != 0:
|
|
bi.append(b % 2)
|
|
b /= 2
|
|
bi.reverse()
|
|
out = 1
|
|
for p in bi:
|
|
out = out * out
|
|
if out > bigunit:
|
|
out /= bigunit
|
|
if p == 1:
|
|
out *= a
|
|
if out > bigunit:
|
|
out /= bigunit
|
|
return out
|
|
|
|
|
|
def fib(x):
|
|
sq5 = 5 ** 0.5
|
|
oa = musq((1 + sq5) / 2, n)
|
|
return oa / sq5
|
|
|
|
n = 0
|
|
a, b = 0, 1
|
|
|
|
while 1:
|
|
a, b = b, a + b
|
|
a %= unit
|
|
b %= unit
|
|
n += 1
|
|
bit = set('#'.join(str(a)).split('#'))
|
|
if len(bit) == 9 and (not '0' in bit):
|
|
try:
|
|
pre = str(fib(n))
|
|
if pre == 'inf':
|
|
break
|
|
except OverflowError:
|
|
print n
|
|
break
|
|
pre = pre[0] + pre[2:]
|
|
bitend = set('#'.join(pre[:9]).split('#'))
|
|
if len(bitend) == 9 and (not '0' in bitend):
|
|
print n, a, pre[:9]
|
|
break |