Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2007-09-03 19:13:57

devil_angel192
Guest

~Prime Numbers~ URGENT

Is there a formula you could use on excel to find prime numbers? If so could you please repost as soon as possible. THANKS

#2 2007-09-03 19:59:54

landof+
Member
Registered: 2007-03-24
Posts: 131

Re: ~Prime Numbers~ URGENT

Explore the different functions, there must be one. and this site has a prime number thing to determine if a number is prime.

No, a prime number list:
http://www.mathsisfun.com/numbers/prime-number-lists.html smile

Last edited by landof+ (2007-09-03 20:00:47)


I shall be on leave until I say so...

Offline

#3 2007-09-04 13:59:27

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: ~Prime Numbers~ URGENT

You could find all the non-primes by finding your 2 tables and your 3 tables and your 5 tables and your 7 tables, etc...  And then the primes would be the numbers you don't find I guess.


igloo myrtilles fourmis

Offline

#4 2007-09-04 22:12:30

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: ~Prime Numbers~ URGENT

There's no formula to find primes, and there's not really any observed pattern to them. As numbers get very large, it also becomes very hard to determine whether they are prime or not.

I did once make a prime number maker in Excel, but it worked by brute force and would only go so far. It went something like this:

Choose how far you want to search for primes. For reference, call this number k. (Note that you can't search further than 65535 because that's when the spreadsheet stops. Also, you'll need a list of all primes less than √k.)

Enter 1 in cell A2, then =A2+1 in cell A3. Fill down until you get to cell A(k+1).

Now put 2 in cell B1, 3 in cell C1, 5 in D1 and so on filling up the cells in row 1 with all the primes until you've gone up to √k. If you don't know all those, you could do a preliminary search with √k as your new k, in which case you'd only need to know primes up to √(√k). The largest prime you'd possibly need to know in that case is 13. For reference, the cell with the biggest prime shall be known as λ1

Now the fun bit. In cell B2, put =ROUNDUP(MOD($A2/B$1,1),0). Now fill this formula across until you reach cell λ2, then down until you reach row (k+1).

You should now be seeing lots of 1s and 0s, where each cell checks the number to its extreme left against the number highest above it. If they're divisible it shows 0, if not it shows 1. One slight annoying bit here: you need to look in each column and manually change the highest 0 you can see into a 1. Sorry about that. You could always tweak the above formula a bit so that it does that for you.

Now go one to the right of λ2, and enter =PRODUCT(A2:λ2). This will show the number in A2 if it's prime, or 0 if it's not. Now fill that formula down to row (k+1) and you'll be done!

That column will now give you a complete list of primes, hidden amongst lots of 0s. If you're proficient in Excel you could use an if function to display "" for composite numbers instead of 0, and if you really wanted you could use conditional formatting to make the primes red and bold or something. But that's the structure of the thing.

Hopefully my explanation wasn't so bad that you can't follow it.

---

Edit: Heh, and I've just noticed that the link above makes this complete post redundant. Ah well. It might be a fun exercise maybe? dunno


Why did the vector cross the road?
It wanted to be normal.

Offline

#5 2007-09-05 03:30:33

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: ~Prime Numbers~ URGENT

There's no formula to find primes, and there's not really any observed pattern to them.

"There are two facts about the distribution of prime numbers which i hope to convince you so overwhelmingly that they will be permanently engraved in your hearts. the first is that despite their simple definition and role as the building blocks of the natural numbers, the prime numbers grow like weeds among the natural numbers, seeming to obey no other law than that of chance, and nobody can predict where they next one will sprout. The second fact is even more astonishing, for it states just the opposite: that the prime numbers exhibit stunning regularity, that there are laws governing their behavior, and that they obey these laws with almost military precision" -D.Zagier


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#6 2007-09-05 10:07:16

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: ~Prime Numbers~ URGENT

That's a nice quote!
Um, I just thought though, by brute force, again, perhaps similar to above, not sure...
Say you start with 2, since that is the smallest prime.
Then you add 2 to it to get four.
Now 3 was skipped, so that is prime.
Now you double 3 to 6, and you add 2 to 4 for 6.
So 5 was skipped, so 5 is prime.
Now you double 5 to 10.
And you add 2 to 6 to make 8 and add 3 to 6 to make 9.
Now 7 was skipped so that is prime.
So then you add 2 to 8 to make 10, and add 3 to 9 to make 12,
and add 5 to 10 to make 15, and double 7 to 14.
Now add 2 to 10 to make 12. 
Now all totals are 12, 14, and 15.
So less than 12,14, and 15, we skipped 11, so 11 is prime.
And then we can continue in this fashion to find other primes...
Pretty fun, huh?


igloo myrtilles fourmis

Offline

Board footer

Powered by FluxBB