Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fib primes
import math
def erathostenes(n):
primes = list(range(2, n+1))
i = 2
while(i <= int(math.sqrt(n))):
if i in primes:
for j in list(range(i*2, n+1, i)):
if j in primes:
primes.remove(j)
i += 1
return primes
def fib(n):
if n < 2:
return n
else:
return fib(n-1) + fib(n-2)
def fib_seq(n):
"""
Calcula la secuencia de fibonacci hasta n
Ejemplo:
>>> fib_seq(10)
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
"""
res = []
for i in range(1, n+1):
res.append(fib(i))
return res
n = 10
fibs = fib_seq(n)
primes = erathostenes(n)
def fib_primes(n):
pass
print(fib_primes(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.