130 Composites with prime repunit property.pl 482 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 12 May 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=130
  7. # Runtime: 0.315s
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use Math::GMPz;
  12. use ntheory qw(gcd is_prime);
  13. my $sum = 0;
  14. my $count = 0;
  15. for (my $n = 2; ; ++$n) {
  16. is_prime($n) && next;
  17. gcd($n, 10) != 1 && next;
  18. Math::GMPz->new('1' x ($n-1)) % $n == 0 or next;
  19. $sum += $n;
  20. last if ++$count == 25;
  21. }
  22. say $sum;