127 abc-hits.pl 733 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 20 May 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=127
  7. # Runtime: 33 min, 6 sec
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use ntheory qw(:all);
  12. sub rad {
  13. my ($n) = @_;
  14. vecprod(map { $_->[0] } factor_exp($n));
  15. }
  16. my $sum = 0;
  17. my $limit = 120_000 - 1;
  18. for my $a (1 .. $limit >> 1) {
  19. for my $b ($a + 1 .. $limit - $a) {
  20. my $c = $a + $b;
  21. if ( !is_square_free($b)
  22. and !is_square_free($c)
  23. and gcd($a, $b, $c) == 1
  24. and rad($a * $b * $c) < $c
  25. ) {
  26. say "$a $b $c = ", $a * $b * $c, " -> ", rad($a * $b * $c);
  27. $sum += $c;
  28. }
  29. }
  30. }
  31. say $sum;