Fun Uncle with Prime Number Lookup

RaviWildcat

Board Regular
Joined
Jun 18, 2010
Messages
132
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
My young nephew is learning about factoring. The principle is that any non - prime number can be broken down into a series of prime numbers. For example, 9 = 3 x 3. My given number (9) can be broken down to a product of prime numbers (3 x 3). 12, can be broken into 2x2x3 and so on.

I'm looking at it like this: (Let's say my given number is in cell d7

Given number
40=IFERROR(IF(MOD(D7,2)=0,D7/2,IF((MOD(D7,3)=0),D7/3,IF((MOD(D7,5)=0),D7/5,".."))),"..")=IFERROR(IF(MOD(E7,2)=0,E7/2,IF((MOD(E7,3)=0),E7/3,"..")),"..")
4020105

you see how I'm first checking mods with prime numbers (2,3,5) - first checking does mod 2 = 0 , then divideby 2, else if mod 3 = 0 then divide by 3 else if mod 5 = 0 then divide by 5 - if none of these things are true then enter ".." then repeat with the result until I get to ..


Any thoughts about referencing a lookup table? I'm thinking about populating a lookup table with a prime number in each column - first the formula checks mod in row 1 of the table (which is 2) then it checks mod in row 2 of the table (which is the next prime number etc.) etc.

That would save me from having a monster if formula!

(There are other approaches that are alternatively cleverer / more cumbersome. I suppose I could write a recursive function in VBA too though the real fun comes from formulas

Any thoughts?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,226,466
Messages
6,191,196
Members
453,646
Latest member
SteenP

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