Skip to content

Instantly share code, notes, and snippets.

@gnp
Created May 14, 2011 05:52
Show Gist options
  • Save gnp/971957 to your computer and use it in GitHub Desktop.
Save gnp/971957 to your computer and use it in GitHub Desktop.
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
----------
$ perl -e '$x = 600851475143; for $i (2..sqrt($x)) { print "$i\n" if $x % $i == 0; }'
71
839
1471
6857
59569
104441
486847
$ perl -e '$x = 486847; for $i (2..sqrt($x)) { print "$i\n" if $x % $i == 0; }'
71
$ perl -e '$x = 104441; for $i (2..sqrt($x)) { print "$i\n" if $x % $i == 0; }'
71
$ perl -e '$x = 59569; for $i (2..sqrt($x)) { print "$i\n" if $x % $i == 0; }'
71
$ perl -e '$x = 6857; for $i (2..sqrt($x)) { print "$i\n" if $x % $i == 0; }'
(nothing)
Answer: 6857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment