346 Strong Repunits.pl 606 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 21 September 2016
  4. # Edit: 16 November 2023
  5. # License: GPLv3
  6. # Website: https://github.com/trizen
  7. # https://projecteuler.net/problem=346
  8. # Runtime: 1.835s
  9. use 5.010;
  10. use strict;
  11. use ntheory qw(fromdigits vecsum);
  12. my %table;
  13. my $limit = 10**12;
  14. for (my $j = 3 ; ; ++$j) {
  15. my $continue;
  16. my $repunit = '1' x $j;
  17. for (my $base = 2 ; ; ++$base) {
  18. my $n = fromdigits($repunit, $base);
  19. $n < $limit or last;
  20. $continue ||= 1;
  21. undef $table{$n};
  22. }
  23. $continue || last;
  24. }
  25. say 1 + vecsum(keys %table);