PDA

View Full Version : Python Challenge: find the largest factor of this number



triptoe
August 22nd, 2007, 05:17 AM
There is a longggggg way to do this and a much easier way. I am just curious if other people do it the same way as me.


Find the largest prime factor of 317584931803 and show the code.. and no cheating!

apetresc
August 22nd, 2007, 06:35 AM
Is Bash allowed? :)

adrian@rootbeer:~$ cat problem.sh
echo `factor 317584931803`
adrian@rootbeer:~$ ./problem.sh
317584931803: 67 829 1459 3919

My answer is 3919!

Out of curiosity, is this question from Project Euler?

EDIT: Oh, oops, I missed the title that says it's a "Python" challenge. Well, you can always just make os calls from Python ;)

triptoe
August 22nd, 2007, 06:54 AM
Is Bash allowed? :)

adrian@rootbeer:~$ cat problem.sh
echo `factor 317584931803`
adrian@rootbeer:~$ ./problem.sh
317584931803: 67 829 1459 3919

My answer is 3919!

Out of curiosity, is this question from Project Euler?

EDIT: Oh, oops, I missed the title that says it's a "Python" challenge. Well, you can always just make os calls from Python ;)

you are close, but none of those are the right answer.

BTW yes it is from Euler... I am doing the challenges one by one.

BTW does anyone know how to find out the length of time it takes to execute a program? Like if i wanted to see how efficient an algorithm was implemented two different ways by timing it.. how would i time it?

apetresc
August 22nd, 2007, 06:58 AM
you are close, but none of those are the right answer.

Er, what? Yes it is...

>>> 67*829*1459*3919
317584931803L
They definitely multiply to the correct value, and they're definitely all prime, and I'm pretty sure the fundamental theorem of arithmetic (unique factorization) still holds for big numbers ;) What makes you think this answer is not right?


BTW does anyone know how to find out the length of time it takes to execute a program? Like if i wanted to see how efficient an algorithm was implemented two different ways by timing it.. how would i time it?
You can use the UNIX 'time' utility. Like so:

adrian@rootbeer:~$ time ./problem.sh
317584931803: 67 829 1459 3919

real 0m0.031s
user 0m0.012s
sys 0m0.004s

Do a "man time" for more details. :)

triptoe
August 22nd, 2007, 07:02 AM
Er, what? Yes it is...

>>> 67*829*1459*3919
317584931803L
They definitely multiply to the correct value, and they're definitely all prime, and I'm pretty sure the fundamental theorem of arithmetic (unique factorization) still holds for big numbers ;) What makes you think this answer is not right?

Ahh you are right i was thinking that 67 * 4740073609 = 31758491803 so 4740073609 was.. oops ... didn't notice the "prime" part :)




BTW does anyone know how to find out the length of time it takes to execute a program? Like if i wanted to see how efficient an algorithm was implemented two different ways by timing it.. how would i time it?
You can use the UNIX 'time' utility. Like so:

adrian@rootbeer:~$ time ./problem.sh
317584931803: 67 829 1459 3919

real 0m0.031s
user 0m0.012s
sys 0m0.004s

Do a "man time" for more details. :)[/QUOTE]

n04touchyy
November 18th, 2009, 01:13 AM
i know the post is old but still

the answer is actually 317584931803 because u dont say that it has to be a prime factor u only say it has to be a factor so 317584931803x1=317584931803.

:p:p:p:p:p:p:p

Can+~
November 18th, 2009, 01:44 AM
i know the post is old but still

the answer is actually 317584931803 because u dont say that it has to be a prime factor u only say it has to be a factor so 317584931803x1=317584931803.

:p:p:p:p:p:p:p


Find the largest prime factor of 317584931803 and show the code.. and no cheating!

Huh? (And you're 2 years late)

Yarui
November 18th, 2009, 02:05 AM
Edit: Wow, I didn't even notice how old this thread was until I replied. I kind of doubt my post is needed anymore.

cariboo
November 18th, 2009, 04:52 AM
Due to the age of the thread, it is now closed