First 9 prime Fibonacci number: Difference between revisions
→{{header|Python}}
(→{{header|Quackery}}: improved efficiency) |
Hellangelx (talk | contribs) |
||
Line 1,168:
=={{header|Python}}==
<syntaxhighlight lang="python">
from math import sqrt
from time import time
start = time()
def
for i in range(2,int(m**0.5)+1):▼
if x <
return False
if x == 2 or x == 3:
return True
return False
if x % i == 0:
return False
return True
▲ if (nr == 0):
d = [1, 1]
f = []
while len(f) < n:
a, b, = b, a + b
d.append(b)
if prime(b):
f.append(b)
print("fib(" + str(len(d)) + "):", b, "(" + str(time() - start) + "s)")
</syntaxhighlight>
{{out}}
<pre>
fib(3): 2 (0.0s)
fib(4): 3 (0.0s)
fib(5): 5 (0.0s)
fib(7): 13 (0.0s)
fib(11): 89 (0.0s)
fib(13): 233 (0.0s)
fib(17): 1597 (0.0s)
fib(23): 28657 (0.0s)
fib(29): 514229 (0.0009968280792236328s)
fib(43): 433494437 (0.0009968280792236328s)
fib(47): 2971215073 (0.003988504409790039s)
fib(83): 99194853094755497 (15.122319459915161s)
Process finished with exit code 0
</pre>
|