LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Harlan Grove
 
Posts: n/a
Default

Bob Phillips wrote...
Here is a routine originally presented by Myrna Larson that I use to test
for primes.

=IsPrime(num)

....

Picky: 1 isn't a prime number any more. See

http://mathworld.wolfram.com/PrimeNumber.html

Next a udf implementing the sieve of Eratosthenes is nice but slow.
Since your udf only handles long integers, the largest possible factor
is

INT(SQRT(2^31-1))

or 46340, which is comfortably less than Excel's max row count (at
least for XL97 and subsequent). So a simple worksheet formula would
suffice.

=SUMPRODUCT(--(MOD(N,ROW(INDIRECT("2:"&INT(SQRT(N)))))=0))=0

That's inefficient. It can be speeded up at the cost of complexity.

=OR(N={2;3;5;7},IF(AND(N10,MOD(N,2)=1),
SUMPRODUCT(--(MOD(N,1+2*ROW(INDIRECT("1:"&INT(SQRT(N)/2))))=0))=0))

If the OP or anyone else needs to check larger numbers, there are much
better tools to use than Excel or VBA.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for current month minus one = Quarter number in a macro. Pank Excel Discussion (Misc queries) 11 June 22nd 05 02:47 PM
doubling a number X number of times Bob Excel Worksheet Functions 1 June 17th 05 12:54 AM
Count Number of Characters in a cell? AHJuncti Excel Discussion (Misc queries) 2 June 16th 05 07:39 PM
Need number of Saturdays and number of Sundays between 2 dates Class316 Excel Worksheet Functions 1 June 10th 05 02:47 AM
Convert week number into calendar month? WickyWick Excel Worksheet Functions 2 November 9th 04 09:01 PM


All times are GMT +1. The time now is 07:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"