Ask your own question, for FREE!
Mathematics 8 Online
OpenStudy (anonymous):

Describe to me a procedure for finding the prime factors of any number, in simple steps.

OpenStudy (anonymous):

bonus if I can actually execute it in Python.

OpenStudy (anonymous):

Python is executable pseudocode

OpenStudy (anonymous):

this is simple man .. what have you tried ?

OpenStudy (anonymous):

I can do it in pseudo-c, but not python. for (i=1; i<sqrt{x}; i++) { if x%i == 0 { cout << x << " is not prime, yo! " << ; } }

OpenStudy (anonymous):

@Dalvoron:Incorrect solution

OpenStudy (anonymous):

that's just the test for primality, not code for prime factorization. :-P

OpenStudy (anonymous):

Aha, misread!

OpenStudy (anonymous):

def primef(n): i = 2 ans = [] while n > 1: if n % i == 0: n /= i ans.append(i) else: for i in xrange(i, n+1): if i**2 < n and n % i == 0: break return ans is this right?

OpenStudy (anonymous):

for prime numbers it just returns the prime number alone

OpenStudy (anonymous):

It's not very optimized :(

OpenStudy (anonymous):

the prime factorization of 999 is 3, 3, 3, and 37

OpenStudy (anonymous):

The prime factorization of 24389 is 29*29*29

OpenStudy (anonymous):

the prime factorization of 23897235782673 is : OverflowError: Python int too large to convert to C long

OpenStudy (anonymous):

how do I fix it?

OpenStudy (anonymous):

what's your purpose for solving this problem?

OpenStudy (anonymous):

just for fun :-D I wanna know a great way of doing it.

OpenStudy (anonymous):

then I can port it to my calculator as an efficient C program.

OpenStudy (anonymous):

I have a very optimized solution using miller rabin and pollard rho but it's for www.spoj.pl/problems/FACT0/ www.spoj.pl/problems/FACT2/ www.spoj.pl/problems/FACT1/ Hence, I can't post here

OpenStudy (anonymous):

:(

OpenStudy (anonymous):

how do I fix my int too large for C long problem

OpenStudy (anonymous):

that's exactly what the spoj problem is about.

OpenStudy (anonymous):

so I need to write a bigint class if I am ever gonna port it to C?

OpenStudy (anonymous):

Yes

OpenStudy (anonymous):

but that would slow things down a little :( walk through the linked list

OpenStudy (anonymous):

No.. learn properly first :)

OpenStudy (anonymous):

I've found nice libraries http://sourceforge.net/projects/msieve/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!