diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-15 19:21:30 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-15 19:21:30 -0500 |
commit | ecb58863c7dc0185708ea52fc6ca956c0f8fb1f7 (patch) | |
tree | 80407d3ad44c34c90cc154a893338443ee097ffa /023.pl | |
parent | 0e52573b8c2a5377f32ffac7ee8db66126844138 (diff) | |
download | projecteuler-ecb58863c7dc0185708ea52fc6ca956c0f8fb1f7.tar.gz projecteuler-ecb58863c7dc0185708ea52fc6ca956c0f8fb1f7.zip |
solution 23
Diffstat (limited to '023.pl')
-rwxr-xr-x | 023.pl | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,25 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Math::Factor::XS qw/factors/; +use List::Util qw/sum/; + +sub abundant { + my ($n) = @_; + return 1 + (sum(factors($n)) || 0) > $n; +} + +my @abundant = grep { abundant($_) } 1..28123; +my %sums; +A: for my $a (@abundant) { + for my $b (@abundant) { + my $n = $a + $b; + next A if $n > 28123; + $sums{$n} = 1; + } +} +my $total = 0; +for my $n (1..28123) { + $total += $n unless exists $sums{$n}; +} +print "$total\n"; |