Prime Factors

Sletsky

New Member
Joined
Mar 5, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Good Day to Everyone,

I am a Adult Student at Western Carolina University. I am taking a basic math class. It is kicking my tail.

I am currently using excel to assist me with formulas and getting answers quickily.

I am trying find some way to take a number Example "2340" and find all the prime factors of that number display them in ascending order in excel.

The other problem is figuring out is the number is prime or not?

How can I do this?

I thank everyone for their time in this matter.

Steve
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
That is a 2 step exercise
a) is the number a prime? There are prime calculators (testers) that would tell you that 2340 is not a prime. IIRC, any number ending in zero is divisible by 2 so that one should be obvious, but I'm no math genius either.
b) Methinks you'd need a vba function for returning only prime divisors of a number. I could find Excel articles that generate a list of primes between two numbers, test if a number is a prime, and so on, but not what you want. What you'd need is code that either looped through a list of primes and tried to divide your number evenly (e.g. 3 would be a prime divisor of 300) or, loop from 2 on up, testing if it's a prime, then doing the division with the prime and testing the result. Maybe that explanation would help you find something, or with luck, someone here has what you need.
 
Upvote 0
You can write a formula to determine primality:

Book1
AB
1NumberPrime?
22340FALSE
Sheet2
Cell Formulas
RangeFormula
B2B2=IF(OR(A2={2,3}),TRUE,NOT(OR(MOD(A2,SEQUENCE(INT(SQRT(A2))-1,,2))=0)))


It's not very efficient, it checks every number from 2 to the square root of the number you're checking. But it should work for most "reasonably" sized numbers you'd encounter in your class. Somewhere in my notes, I've written a macro to test primality of every number up to the limit of Excel's precision (15-digits). It's much faster (and complicated) than this method.

As far as the factorization, that can be done by formulas or a macro too.

Book1
ABCDEFGHIJK
1NumberPrime?FactorsPrime?ExponentSummaryCheck
22340FALSE2TRUE2222340
33TRUE232
44FALSE51
55TRUE1131
66FALSE
79FALSE
810FALSE
912FALSE
1013TRUE1
1115FALSE
Sheet3


The formulas are about the same as the B2 formula, so they're not real efficient, but should work for most reasonably sized numbers. I did this to basically show that it's possible. I didn't supply the formulas since you're in a class. It doesn't really help if you get all the answers provided. Sad to say, but you probably need to work through some of these manually to get the idea.

Take 2340, divide by 2. If it has no remainder, write 2 as a factor and repeat starting with the quotient (1170). Divide 1170 by 2, giving 585. You have another 2 as a factor. 2 no longer is a factor of 585, so go to the next prime, 3, and continue. There are other online sites that will factorize numbers for you, but you're probably doing yourself a disservice if you use them at this stage of your math education.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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