Posted By

cmm7825 on 06/29/10


Tagged


Versions (?)

Problem 23


 / Published in: Perl
 

  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use POSIX qw(floor);
  6. my %abund_hash;
  7. my @abund_list;
  8.  
  9. foreach my $n (1..28123){
  10. my $sum = 1;
  11. foreach (2..floor($n**0.5)){
  12. if($n % $_ == 0){
  13. $sum += $_;
  14. $sum += $n/$_ if (($n/$_) != $_);
  15. }
  16. }
  17. if($sum > $n){
  18. $abund_hash{$n} = 1;
  19. push @abund_list, $n;
  20. }
  21. }
  22.  
  23.  
  24. my $sum = 0;
  25. foreach my $n (1..28123){
  26. my $i = 0;
  27. $sum += $n;
  28. while($n > $abund_list[$i]){
  29. my $key = $n - $abund_list[$i];
  30. if($abund_hash{$key}){
  31. $sum -= $n;
  32. last;
  33. }
  34. $i++;
  35. }
  36. }
  37.  
  38. print "$sum\n";

Report this snippet  

You need to login to post a comment.