Prime Factors

sasha 99

New Member
Joined
Jul 22, 2016
Messages
24
Hi Guys :)
I do these days an analytical research and i need some of help in this issue


I need to find a way to extract the prime factors of numbers with some special conditions .. Let's take an example to make it much more clear


IF i have an an integer number .. let's say 12682


I want to divide 12682 to a specific prime factors


let's say all prime factor which equal to or less than 5 .. the prime factors in this case consist of 2 , 3 , 5 .. any prime number more than 5 will be excluded


However , in some phases the result will not be divisible by 2 , 3 , 5
So this time we will use deduction in stead of division and we will determine a specific number to be used for all deduction calculations in next phases


we will use 7 for all deduction calculations and the process will continue on the same way for all next computational phases until we get to 1







12682 ÷ 2 = 6341
6341 - 7 = 6334

6334 ÷ 2 = 3167
3167 - 7 = 3160

3160 ÷ 2^3 = 395
415 ÷ 5 = 79
79 - 7 = 72

72 ÷ 2^3 = 9
9 ÷ 3^2 = 1

Note :: all result is INTEGER Number


Now , What is the best way to do these calculation and showing it in this sequence ?
so i can know how many time i use 2 , 3 and 5 in division
and how many time i use 7 in deduction


I am sure I will hear a brilliant answer from you , Don't disspoint me :)
Best Regard
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Interesting. Your example has at least one issue, the 415 should be 395. The other question I have is how do you decide to divide by a power of 2, or 3, or 5? Here's a version I came up with using formulas:

ABCDEFGHIJK
112682Factors:235
2Max for GCD819265613125
312682/ 2 =63412
46341- 7 =63341Deduct:7
56334/ 2 =31672
63167- 7 =31601
73160/ 8 =3958
8395/ 5 =795
979- 7 =721
1072/ 9 =89
118/ 8 =18
121
13

<tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
F3=IF(OR(B3=1,B3=""),"",MAX(GCD(B3,$I$2),GCD(B3,$J$2),GCD(B3,$K$2)))
B3=A1
C3=IF(OR(B3=1,B3=""),"",IF(F3>1,"/ "&F3,"- "&$I$4)& " =")
D3=IF(C3="","",IF(LEFT(C3,1)="/",B3/F3,B3-$I$4))
B4=IF(D3="","",D3)
I2=I1^INT(LOG($A$1,I1))

<tbody>
</tbody>

<tbody>
</tbody>



Put your number in A1, and your factors in I1:K1. Put the formulas in as shown, and drag down the columns as needed. This example matches your example until 72, where I divide by 9, and you divide by 8. My rule for selecting which factor to divide by is by finding the largest power of each factor that I can divide by evenly, then taking the largest value of that. If you have a different rule, let us know. According to the Commutative Property, I suppose it doesn't really matter.
 
Last edited:
Upvote 0
All what i can say to you is .. you are a GENIUS :)

"If you have a different rule, let us know. According to the Commutative Property, I suppose it doesn't really matter."

No it does matter at all

I am happy with your answer but it is not a complete happy cuz the ending result is not like yours , although i follow your instruction but something went wrong
NOTE :: I use EXCEL 2007

Here's an screenshot
4564.png
 
Upvote 0
It just looks like you have extra lines. If you want to insert an extra row between each calculation, that's fine, but you need to make sure that the formulas point to the right cells. The B4 formula should probably be in B5.

The easiest way I see to do this is to clear the B:F columns. Now enter the B3:F3 formulas as is. Enter the B4 formula in B5. Now paste the C3:F3 formulas to C5:F5. Now copy B5:F6, so you are copying a row of formulas and a blank row. Now select B7:F100 and paste the formulas, and you should be OK.
 
Upvote 0
It just looks like you have extra lines. If you want to insert an extra row between each calculation, that's fine, but you need to make sure that the formulas point to the right cells. The B4 formula should probably be in B5.

The easiest way I see to do this is to clear the B:F columns. Now enter the B3:F3 formulas as is. Enter the B4 formula in B5. Now paste the C3:F3 formulas to C5:F5. Now copy B5:F6, so you are copying a row of formulas and a blank row. Now select B7:F100 and paste the formulas, and you should be OK.


i did literally what you said , but the result was not as expected
I just kindly ask you ( if possible ) to test the location of formula by yourself .. just to make sure that everything is in the right place
Here's the my screenshoot after your last instructions

Untitled.png
 
Last edited:
Upvote 0
What formulas do you have in C5 and D5?

Here's the appearance of my sheet:

ABCDEFGHIJK
112682Factors:235
2Max for GCD819265613125
312682/ 2 =63412
4
56341- 7 =63341Deduct:7
6
76334/ 2 =31672
8
93167- 7 =31601
10
113160/ 8 =3958
12
13395/ 5 =795
14
1579- 7 =721
16
1772/ 9 =89
18
198/ 8 =18
20
211

<tbody>
</tbody>
Sheet2



and the formulas for each cell:

ABCDEFGHIJK
112682Factors:235
2Max for GCD=I1^INT(LOG($A$1,I1))=J1^INT(LOG($A$1,J1))=K1^INT(LOG($A$1,K1))
3=A1=IF(OR(B3=1,B3=""),"",IF(F3>1,"/ "&F3,"- "&$I$5)& " =")=IF(C3="","",IF(LEFT(C3,1)="/",B3/F3,B3-$I$5))=IF(OR(B3=1,B3=""),"",MAX(GCD(B3,$I$2),GCD(B3,$J$2),GCD(B3,$K$2)))
4
5=IF(D3="","",D3)=IF(OR(B5=1,B5=""),"",IF(F5>1,"/ "&F5,"- "&$I$5)& " =")=IF(C5="","",IF(LEFT(C5,1)="/",B5/F5,B5-$I$5))=IF(OR(B5=1,B5=""),"",MAX(GCD(B5,$I$2),GCD(B5,$J$2),GCD(B5,$K$2)))Deduct:7
6
7=IF(D5="","",D5)=IF(OR(B7=1,B7=""),"",IF(F7>1,"/ "&F7,"- "&$I$5)& " =")=IF(C7="","",IF(LEFT(C7,1)="/",B7/F7,B7-$I$5))=IF(OR(B7=1,B7=""),"",MAX(GCD(B7,$I$2),GCD(B7,$J$2),GCD(B7,$K$2)))
8
9=IF(D7="","",D7)=IF(OR(B9=1,B9=""),"",IF(F9>1,"/ "&F9,"- "&$I$5)& " =")=IF(C9="","",IF(LEFT(C9,1)="/",B9/F9,B9-$I$5))=IF(OR(B9=1,B9=""),"",MAX(GCD(B9,$I$2),GCD(B9,$J$2),GCD(B9,$K$2)))
10
11=IF(D9="","",D9)=IF(OR(B11=1,B11=""),"",IF(F11>1,"/ "&F11,"- "&$I$5)& " =")=IF(C11="","",IF(LEFT(C11,1)="/",B11/F11,B11-$I$5))=IF(OR(B11=1,B11=""),"",MAX(GCD(B11,$I$2),GCD(B11,$J$2),GCD(B11,$K$2)))
12
13=IF(D11="","",D11)=IF(OR(B13=1,B13=""),"",IF(F13>1,"/ "&F13,"- "&$I$5)& " =")=IF(C13="","",IF(LEFT(C13,1)="/",B13/F13,B13-$I$5))=IF(OR(B13=1,B13=""),"",MAX(GCD(B13,$I$2),GCD(B13,$J$2),GCD(B13,$K$2)))
14
15=IF(D13="","",D13)=IF(OR(B15=1,B15=""),"",IF(F15>1,"/ "&F15,"- "&$I$5)& " =")=IF(C15="","",IF(LEFT(C15,1)="/",B15/F15,B15-$I$5))=IF(OR(B15=1,B15=""),"",MAX(GCD(B15,$I$2),GCD(B15,$J$2),GCD(B15,$K$2)))
16
17=IF(D15="","",D15)=IF(OR(B17=1,B17=""),"",IF(F17>1,"/ "&F17,"- "&$I$5)& " =")=IF(C17="","",IF(LEFT(C17,1)="/",B17/F17,B17-$I$5))=IF(OR(B17=1,B17=""),"",MAX(GCD(B17,$I$2),GCD(B17,$J$2),GCD(B17,$K$2)))
18
19=IF(D17="","",D17)=IF(OR(B19=1,B19=""),"",IF(F19>1,"/ "&F19,"- "&$I$5)& " =")=IF(C19="","",IF(LEFT(C19,1)="/",B19/F19,B19-$I$5))=IF(OR(B19=1,B19=""),"",MAX(GCD(B19,$I$2),GCD(B19,$J$2),GCD(B19,$K$2)))
20
21=IF(D19="","",D19)

<tbody>
</tbody>
Sheet4
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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