title: Fibonacci and Prime numbers Python
body: <p>Let <code>F[n]</code> and <code>P[n]</code> be the <code>n</code>th Fibonacci and prime number respectively. There are some values of <code>n</code> for which <code>F[n] % P[n] = 0</code>. </p>
  
  <p>Let the first <code>k</code> indices which satisfies this condition be <code>n_1 &lt; n_2 &lt; ... &lt; n_k</code>.</p>
  
  <p>I want to calculate the sum of the first <code>k</code> indices (i.e. <code>n_1 + ... + n_k</code>). The program is fine for <code>k = 2</code> but too slow for <code>k = 5</code> (as below).</p>
  
  <p>Is there any way I can speed this up?</p>
  
  <pre><code>def primelist(n):
    prime = [True]*n
    for p in range(3,n,2):
      if p**2&gt;n:
      break
    if prime[p]:
      for i in range(p*p,n,2*p):
        prime[i]=False
   return [2]+[p for p in range(3,n,2) if prime[p]]
  l= primelist(100000)
  l.insert(0,0)
  fib = [0,1]
  for i in range(2,len(l)):
  fib.append(fib[i-1]+fib[i-2])
  
  k=0
  sum_=0
  i=1
  while i&lt;len(l):
    if fib[i]%l[i]==0:
      k=k+1
      sum_=sum_+i
    if k==5:
      i=len(l)-1
    i=i+1
  print sum_
  </code></pre>