# Math Help - Table the firts 50 twin primes in Mathematica

1. ## Table the firts 50 twin primes in Mathematica

I want to know how I find, calculate (make a list in Mathematica) for the firts 50 twin primes. If p is a prime and p+2 is a prime they called twin primes. Anybody who can tell me to programing the program Wolfram Mathematica?

I have come this far, so long:

1) I make a new empty list, that I'm calling "twins"

twins = {}

{}

2) I know that the first twins is 3, 5 and put the element to the list:

AppendTo[twins, {3, 5}]

{{3, 5}}

twins

{{3, 5}}

Ok!

3) I'm checking if the next prime 3+2=5 have a twin and use my conditions:

n = 5

5

If[PrimeQ[n] && PrimeQ[n + 2], AppendTo[twins, {n, n + 2}]]

{{3, 5}, {5, 7}}

Ok!

4) Then I'm checking the lengt of my list:

Length[twins]

2

I's ok!

4) It's ok, but the last thing I want to tell Mathematica is to use the comand "While" and do this:

As long as "twins" has less than 50 elements:
Test if both n and n+2 are primes.
If it is so: put {n,n+2} to the list "twins", then increse
n whith 2 and then return the list "twins".

If you can help you can also send me a Mathematica-file whith the solution (nb-file). to anders.skoog@vaxjofria.se or anders.k.m.skoog@home.se , or just write it down here at the forum. Thanks.

2. Originally Posted by Bigas
I want to know how I find (make a table or a list in Mathematica) for the firts 50 twin primes. If p is a prime and p+2 is aprime they called twin primes. Anybody who can tell me to find the first 50 in the program Wolfram Mathematica?
Use Excel, but make sure you have enough memory. I got the first 20 twin primes...

3/5

5/7

11/13

17/19

29/31

41/43

59/61

71/73

101/103

107/109

137/139

149/151

179/181

191/193

197/199

227/229

239/241

269/271

281/283

3. Sorry for those gaps, I copied it straight out of Excel.. Here are the top 35 twin primes: Twin prime - Wikipedia, the free encyclopedia

4. Originally Posted by colby2152
Sorry for those gaps, I copied it straight out of Excel.. Here are the top 35 twin primes: Twin prime - Wikipedia, the free encyclopedia

I think you misunderstod me. I have to calculate the first 50 prime twins i Mathematica. Anybody who can help me how to do?

5. Hey! Why don't you use the Help in Mathematica?? If you had typed "twin prime" in the search you would have probably found the command you need:
Code:
Select[Range[1000], PrimeQ[#] && NextPrime[#] == 2 + # &]
And if you want the first 50 twin primes then choose a big enough number instead of 1000 for example 100000 and modify a little bit in the Select command to display only the first 50 numbers:
Code:
Select[Range[100000], PrimeQ[#] && NextPrime[#] == 2 + # &, 50]

6. Originally Posted by Bigas
I think you misunderstod me. I have to calculate the first 50 prime twins i Mathematica. Anybody who can help me how to do?
I am not familiar with Mathematica. I am not sure if what I did in Excel could help you out, but you could do an if/then/while/for (whatever) loop starting at n=2, going from i=2 to i=n-1, and compare n/i - integer(n/i) and use that to see if any numbers are prime. They will be prime if none of those calculations come up as an integer. Then you can do another loop looking at a prime and the number two ahead of it.