Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Prime Numbers?

Hello,
I am looking for a function that will return a prime
number in Excel. Is there such a thing? Is it possible
to obtain prime numbers in a simple and easy way?

Keith
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Prime Numbers?

Hi Keith
=3
<vbg
but I don't thinks this is what you want. what are you trying to
achieve (generating prime numbers within a range, getting the largest
prime within a range, sieving primes, etc?). You may have a look at
http://www.utm.edu/research/primes/

Frank

Keith wrote:
Hello,
I am looking for a function that will return a prime
number in Excel. Is there such a thing? Is it possible
to obtain prime numbers in a simple and easy way?

Keith



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Prime Numbers?

Keith,

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

=IsPrime(num)

returns True or False.

Function IsPrime(TestNum As Long)
Dim PrimeCnt As Long
Dim y As Long
Dim x As Long
Dim i As Long
Dim Flag As Boolean
Dim Primes() As Long
Dim NumStop As Double
ReDim Primes(1 To 2)

NumStop = Sqr(TestNum)
If TestNum = 1 Or TestNum = 2 Or TestNum = 3 Or TestNum = 5 Then
IsPrime = True
Exit Function
End If
Primes(1) = 2
Primes(2) = 3
PrimeCnt = 2
x = 3

Do
x = x + 2
For y = 3 To Sqr(x) Step 2
If x Mod y = 0 Then GoTo NoPrime1
Next y
PrimeCnt = PrimeCnt + 1
ReDim Preserve Primes(1 To PrimeCnt)
Primes(PrimeCnt) = x
NoPrime1:
Loop Until Primes(PrimeCnt) NumStop

For i = LBound(Primes) To UBound(Primes)
If TestNum Mod Primes(i) = 0 Then
IsPrime = False
Exit Function
End If
Next
IsPrime = True
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Keith" wrote in message
...
Hello,
I am looking for a function that will return a prime
number in Excel. Is there such a thing? Is it possible
to obtain prime numbers in a simple and easy way?

Keith



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Prime Numbers?

Hi Keith,

If you do a search on Internet you will find lists of prime numbers and
agorithms to create such a list.
What exactly do you require? Just one prome numer or a function that takes a
prime number randomly from a list?

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Keith" wrote in message
...
Hello,
I am looking for a function that will return a prime
number in Excel. Is there such a thing? Is it possible
to obtain prime numbers in a simple and easy way?

Keith



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Prime Numbers?


"Keith" wrote in message
...
Hello,
I am looking for a function that will return a prime
number in Excel. Is there such a thing? Is it possible
to obtain prime numbers in a simple and easy way?

Keith



see the code at the bottom of this page

http://members.chello.nl/n.sterk/Exc...xcel_files.htm


Keith Willshaw




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Prime Numbers?

Thank you to all who replied.
I actually am attempting to generate a list of primes, so
the routine that tests for primes will work, and I'll also
look at the other suggestions.

thanks very much,

keith
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Prime Numbers?

Keith wrote:
Thank you to all who replied.
I actually am attempting to generate a list of primes, so
the routine that tests for primes will work, and I'll also
look at the other suggestions.

thanks very much,

keith


Hi Keith
I would suggest to import an existing list of primes. e.g.
http://www.utm.edu/research/primes/lists/small/1000.txt

Frank

  #8   Report Post  
Posted to microsoft.public.excel.programming
ds ds is offline
external usenet poster
 
Posts: 2
Default Prime Numbers?

Here's another new suggestion:

I do not quite know if this software can contribute,
but i just wanted to let you know, that we developed a collection
of functions (library, dll) for working with real big numbers.
(...numbers bigger than the normal data types a programmer can handle.)

It was made for Visual Basic, but can be used in
any language that can invoke a .DLL (such as C++, VBA in Excel, Access or
whatever)

It's the only DLL available for Windows for UNLIMITED BIG NUMBERS
with functions such as: +/-* Power2, Power10, MOD DIVIDE, ISPRIME, COMPARE,
Xor etc...

Calculations are sometimes even faster than you are used to, cause
everything was made in assembly. It's shareware and it is online on
http://www.big-numbers.com

David

"Frank Kabel" schreef in bericht
...
Keith wrote:
Thank you to all who replied.
I actually am attempting to generate a list of primes, so
the routine that tests for primes will work, and I'll also
look at the other suggestions.

thanks very much,

keith


Hi Keith
I would suggest to import an existing list of primes. e.g.
http://www.utm.edu/research/primes/lists/small/1000.txt

Frank



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Prime Numbers?

Where can I get the function
=IsPrime(num

I typed it in a cell and got an error message
Is there an add-on for more functions in Excel

I want an IF test for a cel
=IF(IsPrime(B1),"Prime","Composite")
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Prime Numbers?

Hi Nia,

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

=IsPrime(num)

returns True or False.

Function IsPrime(TestNum As Long)
Dim PrimeCnt As Long
Dim y As Long
Dim x As Long
Dim i As Long
Dim Flag As Boolean
Dim Primes() As Long
Dim NumStop As Double
ReDim Primes(1 To 2)

NumStop = Sqr(TestNum)
If TestNum = 1 Or TestNum = 2 Or TestNum = 3 Or TestNum = 5 Then
IsPrime = True
Exit Function
End If
Primes(1) = 2
Primes(2) = 3
PrimeCnt = 2
x = 3

Do
x = x + 2
For y = 3 To Sqr(x) Step 2
If x Mod y = 0 Then GoTo NoPrime1
Next y
PrimeCnt = PrimeCnt + 1
ReDim Preserve Primes(1 To PrimeCnt)
Primes(PrimeCnt) = x
NoPrime1:
Loop Until Primes(PrimeCnt) NumStop

For i = LBound(Primes) To UBound(Primes)
If TestNum Mod Primes(i) = 0 Then
IsPrime = False
Exit Function
End If
Next
IsPrime = True
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Nia" wrote in message
...
Where can I get the function?
=IsPrime(num)

I typed it in a cell and got an error message.
Is there an add-on for more functions in Excel?

I want an IF test for a cell
=IF(IsPrime(B1),"Prime","Composite")



Reply
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
Largest Prime Number Gary''s Student Excel Discussion (Misc queries) 10 November 24th 08 01:26 AM
prime number danpt Excel Discussion (Misc queries) 8 October 10th 08 05:07 PM
How to determine the prime numbers? Eric Excel Discussion (Misc queries) 9 October 4th 07 07:48 PM
How do I test for a prime number? Stephen P Thomas Excel Worksheet Functions 3 July 13th 05 11:43 PM
PRIME FACTOR Ted Moise Excel Worksheet Functions 1 October 29th 04 06:40 AM


All times are GMT +1. The time now is 12:11 PM.

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

About Us

"It's about Microsoft Excel"