0
$\begingroup$

This is most likely a piece of cake for you guys, but it is difficult for me.

Related to a math problem, I examine if Fibonacci[n]*Fibonacci[n] + <some number K between 1 and 99> is a prime, and all this for first 1000 Fibonacci numbers only.

For example, this code: (K=1)

Select[Table[Fibonacci[n], {n, 1, 1000}], PrimeQ[#*# + 1] &]

returns

{1, 1, 2}

This code: (K=2)

Select[Table[Fibonacci[n], {n, 1, 1000}], PrimeQ[#*# + 2] &]

returns

{1, 1, 3, 21, 6765, 32951280099, \ 971183874599339129547649988289594072811608739584170445, \ 1082459262056433063877940200966638133809015267665311237542082678938909\ }

This code: (K=3)

Select[Table[Fibonacci[n], {n, 1, 1000}], PrimeQ[#*# + 3] &]

returns

{2, 8, 3524578, 27777890035288, \ 2011595611835338993891308327102733537615455242513357158345612749706882\ 9146295425939723629305572732574726246290673965789878845363842331040064\ 16432124798818261534841714338, \ 2949592466076064248964701302014885591673737506156850406413751530665307\ 5810241060939483954895520932111023343610904846943097162533007651451709\ 723277579925520157875345780869307228929160}

And this code: (K=99)

Select[Table[Fibonacci[n], {n, 1, 1000}], PrimeQ[#*# + 99] &]

returns

{2, 8, 3524578, 6557470319842, \ 4286863412788815942499567477797350205106309231244244822408841055026686\ 7672}

I need to get all results from 1 to 99, then count elements of each answer, and display these in the following (or similar) form:

   K    number of primes
   1            3
   2            8
   3            6
   .            .
   .            .
  99            5

I appreciate your help.

$\endgroup$

1 Answer 1

3
$\begingroup$
fibs2 = Fibonacci@Range@1000^2;
tab = Table[{k, Count[fibs2 + k, _?PrimeQ]}, {k, 1, 99}];

TableForm[tab, TableHeadings -> {None, {"K", "number of primes"}}]

(welcome back)

$\endgroup$
1
  • $\begingroup$ Hey, you managed to put together the answer faster than the code from the answer (with 99 replaced with 299) executed on my old laptop! That's wizardry! Thanks a lot for the magic! $\endgroup$
    – VividD
    Jan 4, 2015 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.