First 9 prime Fibonacci number: Difference between revisions
Content added Content deleted
Hellangelx (talk | contribs) |
Hellangelx (talk | contribs) |
||
Line 1,409: | Line 1,409: | ||
<syntaxhighlight lang="python"> |
<syntaxhighlight lang="python"> |
||
2 things: |
2 things: |
||
for the Fibonacci sequence: an even number is following after 2 odd numbers. Eliminate time to check whether it is prime or not because even numbers are not primes. |
"""for the Fibonacci sequence: an even number is following after 2 odd numbers. Eliminate time to check whether it is prime or not because even numbers are not primes. |
||
for prime numbers: it becomes bigger and bigger. The original algorithm will be slow for super big number. In this case, I use Miller Rabin primality test. |
for prime numbers: it becomes bigger and bigger. The original algorithm will be slow for super big number. In this case, I use Miller Rabin primality test. |
||
P/S: I am not surprised. It is fast but still cannot compare to other languages such as C++ or Rust or .... After all, Python is still slow :P |
P/S: I am not surprised. It is fast but still cannot compare to other languages such as C++ or Rust or .... After all, Python is still slow :P""" |
||
def miller_rabin(n, k=5): |
def miller_rabin(n, k=5): |