Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created June 23, 2019 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/02202b34d4c4cbcdff9632c1a2ac387c to your computer and use it in GitHub Desktop.
Save dogbert17/02202b34d4c4cbcdff9632c1a2ac387c to your computer and use it in GitHub Desktop.
# What is the largest prime factor of the number 600851475143 ?
use v6;
my $num = 600_851_475_143;
my $val = $num;
my @factors = ();
while ([*] @factors) != $num {
push @factors, (2...*).first(-> $x { $val %% $x && $x.is-prime });
$val = $val div @factors[*-1];
}
say @factors.max; # remove max to see all prime fact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment