fork download
  1. use strict;
  2. use warnings;
  3.  
  4. my $magic = 600851475143;
  5.  
  6. sub largestprimef($);
  7. sub max($$);
  8.  
  9. print largestprimef($magic);
  10. sub largestprimef($)
  11. {
  12. my $n = shift;
  13.  
  14. my $i;
  15. return largestprimef(max(2, $n/2) if($n % 2 == 0)); #UPDATE: There was a bug here where I didn't missed the recursive call. Corrected 20th April 2009.
  16. my $sn = int(sqrt($n));
  17.  
  18. for ($i = 3; $i <= $sn; $i += 2) { if($n % $i == 0) { last; } } if($i > $sn) #loop ran over, means the number is prime
  19. {
  20. return $n;
  21. }
  22. else
  23. {
  24. return max($i, largestprimef($n/$i));
  25. }
  26. }
  27.  
  28. sub max($$)
  29. {
  30. return (sort { $a <=> $b }(@_))[1];
  31. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
===SORRY!===
Unable to find module 'strict' in the @*INC directories.
(@*INC contains:
  /home/3aACBu/.perl6/lib
  /usr/lib/parrot/2.7.0/languages/perl6/lib
  .)
stdout
Standard output is empty