close

I am looking for an add-in that would allow you to find the highest
prime divisor in a number. ie 68, 2x2x17, so 17 is the highest prime.
Any help would be much appreciated...Here is a function that I adapted from something I found in a Google

Function MaxPrime(limit As Long)
Dim PrimeCnt As Long
Dim y As Long
Dim x As Long
Dim Primes

ReDim Primes(1 To limit)
PrimeCnt = 1
If limit Mod 2 = 0 Then
Primes(PrimeCnt) = 2
PrimeCnt = PrimeCnt 1
End If
If limit Mod 3 = 0 Then
Primes(PrimeCnt) = 3
PrimeCnt = PrimeCnt 1
End If
x = 3
Do
x = x 2
For y = 3 To Sqr(x) Step 2
If x Mod y = 0 Then GoTo noprime
Next y
If limit Mod x = 0 Then
Primes(PrimeCnt) = x
PrimeCnt = PrimeCnt 1
End If

noprime:
Loop Until x gt; limit

MaxPrime = Application.Max(Primes)

End Function--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

gt; wrote in message ups.com...
gt; I am looking for an add-in that would allow you to find the highest
gt; prime divisor in a number. ie 68, 2x2x17, so 17 is the highest prime.
gt; Any help would be much appreciated...
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()