Posted By

cmm7825 on 06/01/10


Tagged


Versions (?)

Problem 21


 / Published in: Perl
 

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use POSIX qw(floor);
  5.  
  6. my $sum = 1;
  7. my %hash;
  8.  
  9. foreach my $n (1..10000){
  10. $sum = 1;
  11. foreach (2..floor($n**0.5)){
  12. if($n % $_ == 0){
  13. $sum += $_;
  14. $sum += $n/$_;
  15. }
  16. }
  17. $hash{$n} = $sum;
  18. }
  19.  
  20. my $total = 0;
  21. foreach my $key (keys %hash){
  22. my $value2 = 0;
  23. my $value1 = $hash{$key};
  24. if($value1<10000){
  25. $value2 = $hash{$value1};}
  26. if($key == $value2 && $value1 != $value2){
  27. $total += $key;}
  28. }
  29.  
  30. print "$total\n";

Report this snippet  

You need to login to post a comment.