Largest Prime Number

G

Gary''s Student

What is the largest prime number that can be represented numerically in Excel?

I realize there are an infinite quantity of prime numbers, but I am not
concerned with primes that are so large that they can only be represented as
Text.

Thanks in advance.
 
J

Joel

Gary: I did some experimenting and I think the answer is 99999999977. Excel
says the accuracy is 15 places which I assume is binary which would mean that
the largest number is &HFFFF. I tried larger number and found the largest
number is 99999999999 (eleven 9's). Twelve 9's gave me scientific notation
which means the number was larger than the accuracy of excel.

I then wrote a quick program to find the largest number less than
99999999999. See program below.

Sub getprime()

Num = 99999999999#
Prime = 0
For N = Num To 1 Step -2
SqareRoot = Sqr(Num)
Prime = True
For N1 = 3 To SqareRoot step 2
Div = Int(N / N1)
Mult = Div * N1
If N = Mult Then
Prime = False
Exit For
End If
Next N1
If Prime = True Then
Prime = N
Exit For
End If
Next N

MsgBox ("Prime = " & Prime)

End Sub
 
M

Mike H

Hi,

On the assumption you mean up to a max of 15 digits then the largest 10 are:-

999999999999989
999999999999947
999999999999883
999999999999877
999999999999827
999999999999809
999999999999659
999999999999643
999999999999577
999999999999571

Mike


Mike
 
G

Gary''s Student

Thanks!
--
Gary''s Student - gsnu200815


Mike H said:
Hi,

On the assumption you mean up to a max of 15 digits then the largest 10 are:-

999999999999989
999999999999947
999999999999883
999999999999877
999999999999827
999999999999809
999999999999659
999999999999643
999999999999577
999999999999571

Mike


Mike
 
G

Gary''s Student

Thanks!
--
Gary''s Student - gsnu200815


Joel said:
Gary: I did some experimenting and I think the answer is 99999999977. Excel
says the accuracy is 15 places which I assume is binary which would mean that
the largest number is &HFFFF. I tried larger number and found the largest
number is 99999999999 (eleven 9's). Twelve 9's gave me scientific notation
which means the number was larger than the accuracy of excel.

I then wrote a quick program to find the largest number less than
99999999999. See program below.

Sub getprime()

Num = 99999999999#
Prime = 0
For N = Num To 1 Step -2
SqareRoot = Sqr(Num)
Prime = True
For N1 = 3 To SqareRoot step 2
Div = Int(N / N1)
Mult = Div * N1
If N = Mult Then
Prime = False
Exit For
End If
Next N1
If Prime = True Then
Prime = N
Exit For
End If
Next N

MsgBox ("Prime = " & Prime)

End Sub
 
D

Dana DeLouis

Gary''s Student said:
What is the largest prime number that can be represented numerically in Excel?

I realize there are an infinite quantity of prime numbers, but I am not
concerned with primes that are so large that they can only be represented as
Text.

Thanks in advance.

Hi. Just to be different....
Numerically, and with no "Text", vba can represent a larger number.


Sub Demo()
Dim n

'// Not a Prime of course
n = CDec(491848789357#) * 13 * 9241 * 464773 * 2884993

'// Adding 10 is a Prime, and the largest Prime in Excel vba
n = n + 10
Debug.Print FormatNumber(n, 0, , , vbTrue)

'ie 79,228,162,514,264,337,593,543,950,319

'// Adding 16 is ok.
n = n + 16

'// Adding one more puts us at overfolw
n = n + 1
End Sub

- - -
:>)
Dana DeLouis
 
G

Gary''s Student

Thanks!
--
Gary''s Student - gsnu200815


Dana DeLouis said:
Hi. Just to be different....
Numerically, and with no "Text", vba can represent a larger number.


Sub Demo()
Dim n

'// Not a Prime of course
n = CDec(491848789357#) * 13 * 9241 * 464773 * 2884993

'// Adding 10 is a Prime, and the largest Prime in Excel vba
n = n + 10
Debug.Print FormatNumber(n, 0, , , vbTrue)

'ie 79,228,162,514,264,337,593,543,950,319

'// Adding 16 is ok.
n = n + 16

'// Adding one more puts us at overfolw
n = n + 1
End Sub

- - -
:>)
Dana DeLouis
 
S

Shane Devenshire

Hi,

Because Excel switches to scientific notation does not mean the it can't
handle larger numbers or that its accuracy is only out to 11 places. In the
spreadsheet the accuracy could be out to 15 places just as the Help system
states. I say could because whether a result is accurate to 15 decimals
depends on what your calculating and you its handled in binary.

Cheers,
Shane Devenshire
 
J

Jerry W. Lewis

The largest prime number that can be represented in IEEE double precision is
=2^53-111
This value is 9007199254740881, which has 16 decimal digits, so Excel will
not correctly display the final digit, since it displays no more than 15
decimal digits, but the formula will give you the correct value, as can be
verified by appropriate subtraction.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top