Hi Luis,
Thank you for sharing your formula for possible primes:
p = n^8-1+n^4.
I decided to explore it a bit further :-)
​
First let’s find a value of integer n that yields a Fermat prime in the 1st 60 primes.
Mathematica will give us the kth prime number with the function Prime[].
We use Table:
In[]:=
FpTable=Table[Solve[
n
2
-1Prime[k],n,PositiveIntegers],{k,1,60}]
Out[]=
{{},{{n2}},{},{{n3}},{},{},{},{},{},{},{{n5}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n7}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}
or get the same result with Map:
In[]:=
FpTable=Solve[
n
2
-1Prime[#],n,PositiveIntegers]&/@Range[1,60]
Out[]=
{{},{{n2}},{},{{n3}},{},{},{},{},{},{},{{n5}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n7}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}
Either way, we found that for Format’s formula n  2, 3, 5, and 7 works!
​
And for the Luis formula:
In[]:=
LpTable=Table[Solve[
8
n
-1+
4
n
Prime[k],n,PositiveIntegers],{k,1,60}]
Out[]=
{{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n2}},{},{}}
We find n  2 works -- apparently your formula is a bit more sparse than Fermat’s in the lower range.
​
Now let’s clean the output from the Table.
First of all, those empty solutions are boring.
Here I’m using Map to eliminate them in an If[] statement:
In[]:=
FpTable=If[#{},Nothing,#]&/@Table[Solve[
n
2
-1Prime[k],n,PositiveIntegers],{k,1,60}]
Out[]=
{{{n2}},{{n3}},{{n5}},{{n7}}}
We’d like to know what k the n belongs to, so I’m inserting k in the Table definition.
See how I enclosed k with Solve using brackets?
But now the solution is in the 2nd part of each Table element, so the test in the If statement was updated to #[[2]].
You can read more about those brackets in the Mathematica documentation for Part.
In[]:=
FpTable=If[#[[2]]{},Nothing,#]&/@Table[{k,Solve[
n
2
-1Prime[k],n,PositiveIntegers]},{k,1,60}]
Out[]=
{{2,{{n2}}},{4,{{n3}}},{11,{{n5}}},{31,{{n7}}}}
Well that’s better, but notice how Solve[] outputs solutions in a List; e.g. {{n2}} ?
We know that both the Luis and the Fermat formula are increasing, so let’s restrict to the first solution.
See how I was very specific about what I wanted at the end of the If statement?
In[]:=
FpTable=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[
n
2
-1Prime[k],n,PositiveIntegers]},{k,1,60}]
Out[]=
{{2,n2},{4,n3},{11,n5},{31,n7}}
and for the Luis formula:
In[]:=
LpTable=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[
8
n
-1+
4
n
Prime[k],n,PositiveIntegers]},{k,1,60}]
Out[]=
{{58,n2}}
Well, the 1st 60 primes is interesting, but how about the 1st 10000?
Let’s time it.
In[]:=
time1=AbsoluteTime[];​​​​LpTable1000=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[
8
n
-1+
4
n
Prime[k],n,PositiveIntegers]},{k,1,10000}];​​​​time2=AbsoluteTime[];​​​​Print[];​​Print["elapsed time = ",(time2-time1)/60.," minutes"];​​Print["LpTable = ",LpTable];
elapsed time = 0.34039 minutes
LpTable = {{58,n2}}
​
Whew!