![]() |
An add-in that allows you to find the highest prime in a number
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... |
An add-in that allows you to find the highest prime in a number
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 limit MaxPrime = Application.Max(Primes) End Function -- HTH Bob Phillips (remove nothere from email address if mailing direct) wrote in message ups.com... 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... |
All times are GMT +1. The time now is 03:36 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com