i'm looking to determine if a number is prime or not...
i thought of testing with the mod function in an adjacent cell...but i'm not sure how to do...?
???
thank you.
i'm looking to determine if a number is prime or not...
i thought of testing with the mod function in an adjacent cell...but i'm not sure how to do...?
???
thank you.
Re: Mod Function
Googling through up a few formula.
This one appears to work.
=AND(MOD(A1,ROW(INDIRECT("2:"&INT(A1^0.5)))))
Re: Mod Function
works like a "charm"...!
thank you...
Re: Mod Function
Andy
Is that formula meant to test if a number is prime?
When I try it I get some strange results.
eg 2,3 - not prime, 15, 21,25, 33 - prime
Perhaps I didn't use the formula right, all I did was pop it in B1 and then enter various numbers in A1.
Re: Mod Function
Google found this too:
**********************************
POWER FORMULA TECHNIQUE
by Bob Umlas
This array formula returns TRUE if the number in cell A1 is a prime number.
=OR(A1=2,A1=3,ISNA(MATCH(TRUE,A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))=
INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))),0)))
Use it as a conditional formatting formula, with A1 as the active cell
in the selection to be formatted.
Here's how Bob's amazing formula works. In a nutshell, the number is
divided by all potential prime factors, and the resulting array is tested
to see whether it contains a whole number. If is does, you have a prime
number. A limitation of this formula is that it cannot test numbers that
are greater than 65535^2. This is due to the array size constraint in
Excel 97/2000.
**********************************
Re: Mod Function
Sicarii
Again that's telling me 33 is prime.:confused:
Re: Test If Number Is Prime
I was in my prime at 33... :grin:
Re: Test If Number Is Prime
Oops I forget to add the cavet of Array formula.
I also note that numbers it deals with values greater than 5
Re: Test If Number Is Prime
Sorry, it's an array formula...
Re: Test If Number Is Prime
Ah, should of thought of that.:oops:
Was starting to think that the basic foundations of mathematics had seismically shifted overnight and my (ancient) maths degree was worthless.
Oh, wait a minute that degree is practically worthless.:roll:
Never got me a job anyway, and the most common comment is 'So you're a teacher then?'.:crying:
:dolphin: :dolphin: :dolphin: :dolphin:
Re: Test If Number Is Prime
That's a very clever and compact formula, Andy.
Don’t have an account yet? Register yourself now and be a part of our community!