InterviewSolution
Saved Bookmarks
| 1. |
Given a positive integer, write a function that computes the prime factors that can be multiplied together to get back the same integer. |
|
Answer» def primeFactorization(num): factors = [ ] lastresult = num # 1 is a special case if num == 1: return [ ] while True: if lastresult == 1: break c = 2 while True: if lastresult % c = = 0: break c += 1 factors.append(c) lastresult/= c return factors |
|