excel problem, prime numbers

mwilliams232

New Member
Joined
Dec 8, 2002
Messages
2
hey,

does anyone know how to make an excel spreadsheet that inputs any number and in another cell outputs if the number is prime or not. thanks.

-matt w.
 
dude, I needed the same thing as you, so without all those hard to execute things mentioned previously, see what I was able to figure out:
=IF(ROUND(A1/2,0)=A1/2,"N",IF(ROUND(A1/3,0)=A1/3,"N",IF(ROUND(A1/5,0)=A1/5,"N",IF(ROUND(A1/7,0)=A1/7, "N", "P"))))

basically it returns P if its a prime, and N if it is not.
it works for numbers from 11 to 100, if you need more number than 100, you should add the next primes ( I went from 3 to 7, you will need to add 11, etc ).

hope it helps

P.S. having in mind in Excel you can nest up to 64 times - you should be able to get the "P" or the "N" for all the numbers till 92000 or so - 64th prime number is 307, so 307*307=92000+
 
Last edited:
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It's hard to believe that there are still people posting on an 8 year old thread and making the task far more complicated than needed.

1 simple array formula can determine if any number below 1048576 (65536 for excel 03 users) is prime or not,

{=IF(SUM(IF(MOD(A1,ROW(INDIRECT("1:"&A1)))=0,1))<=2,"Prime","Not Prime")}
 
Upvote 0
It's hard to believe that there are still people posting on an 8 year old thread and making the task far more complicated than needed.

1 simple array formula can determine if any number below 1048576 (65536 for excel 03 users) is prime or not,

{=IF(SUM(IF(MOD(A1,ROW(INDIRECT("1:"&A1)))=0,1))<=2,"Prime","Not Prime")}


cool, never had time to learn those array formulas...
thanks dude
 
Upvote 0
dude, I needed the same thing as you, so without all those hard to execute things mentioned previously, see what I was able to figure out:
=IF(ROUND(A1/2,0)=A1/2,"N",IF(ROUND(A1/3,0)=A1/3,"N",IF(ROUND(A1/5,0)=A1/5,"N",IF(ROUND(A1/7,0)=A1/7, "N", "P"))))

basically it returns P if its a prime, and N if it is not.
it works for numbers from 11 to 100, if you need more number than 100, you should add the next primes ( I went from 3 to 7, you will need to add 11, etc ).

hope it helps

P.S. having in mind in Excel you can nest up to 64 times - you should be able to get the "P" or the "N" for all the numbers till 92000 or so - 64th prime number is 307, so 307*307=92000+

If this is a joke - barely funny
If you are serious - I'm speechless

Gene Klein
 
Upvote 0
If this is a joke - barely funny
If you are serious - I'm speechless

Gene Klein


hhheheh, who knows:)

basically represnts a simple way for doing stuff without fancy formulas... and indeed simply, but time consuming

not all ppl use array formulas... f that need to learn those:)
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top