Thread: prime number
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default prime number

On Wed, 8 Oct 2008 21:31:00 -0700, Sheeloo
wrote:

No.

Thanks to Chip Pearson for providing this formula
________________
The formula below will test the number in cell C8 and return the word prime
if it is prime or the string not prime if the number is not prime.

=IF(OR(C8=1,C8=2,C8=3),"prime",
IF(AND((MOD(C8,ROW(INDIRECT("2:"&C8-1)))<0)),"prime","not prime"))

This is an array formula, so you must press CTRL SHIFT ENTER rather than
just ENTER when you first enter the formula and whenever you edit it later.
If you do this properly, Excel will display the formula enclosed in curly
braces { }.


Of course, this formula seems to be limited to the range of numbers up to the
number of rows in the spreadsheet + 1.

In Excel 2007, it returns a REF error for values 1,048,577
--ron