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