Skip to content Skip to sidebar Skip to footer

Prime Factorization In Python

I found this piece of code online and it basically functions by factorizing a given number into its prime factors and lists them. def primefactors(x): factorlist=[] loop=2 while lo

Solution 1:

x /= loop is equivalent to x = x / loop.

Since you are dividing x by loop until loop is no longer a factor of x, by the time you get to any composite number, you'll have already divided out all of its prime factors, so the composite number will not be a factor of the current value of x.

Solution 2:

/= Divide AND

It divides left operand with the right operand and assign the result to left operand

example : c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a

Post a Comment for "Prime Factorization In Python"