Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

Write python code to display the prime factors of any user given number

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
I would start with the highest prime that is close to half of the number and work down. Also, you might want to check if it is prime right off.
These were from a couple of years back, but should still work. def makeprimelist(bound): max_ndx = (bound - 1) / 2 sieve = [True] * (max_ndx + 1) for ndx in range(int(bound ** 0.5) / 2): if sieve[ndx]: num = ndx * 2 + 3 sieve[ndx+num:max_ndx:num] = [False] * ((max_ndx-ndx-num-1)//num + 1) return [2] + [ndx * 2 + 3 for ndx in range(max_ndx) if sieve[ndx]] def factors(x,unique=0): if x ==1:return [1] pl = makeprimelist(x) tmp = x factors=[] while tmp > 1: for p in pl: if tmp%p==0: factors.append(p) tmp=tmp/p if unique: factors.sort() i=0 while i < len(factors)-1: if i < len(factors) and factors[i]==factors[i+1]: factors.remove(factors[i]) factors[i]=factors[i]*factors[i] else: i+=1 return factors
and i make no claims that that is the best way to implement either of the functions just the ones i used when i was learning python and playing on projecteuler.net

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question