179 Consecutive positive divisors.pl 497 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 14 August 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # Find the number of integers 1 < n < 10^7, for which n and n + 1 have the same number of positive divisors.
  7. # https://projecteuler.net/problem=179
  8. # Runtime: 6.453s
  9. use 5.010;
  10. use strict;
  11. use ntheory qw(divisors);
  12. my $count = 0;
  13. my $prev = 1;
  14. for my $n (2 .. 10**7 - 1) {
  15. my $dc = divisors($n);
  16. ++$count if $dc == $prev;
  17. $prev = $dc;
  18. }
  19. say $count;