Guest User

Untitled

a guest
Aug 8th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.02 KB | None | 0 0
  1.  
  2. #!/usr/bin/perl
  3. @abcheck;
  4. for $i (1..28123) {
  5.         my @div1;
  6.         my $d1;
  7.         my $sum1 = 0;
  8.         my $n1 = ($i/2);
  9.         for $j (1..$n1) {
  10.                 push(@div1,$j) if ($i % $j == 0);
  11.         }
  12.         for $d1 (@div1) {
  13.                 $sum1 += $d1;
  14.         }
  15. #       print "Divisors of $i are @div1, which add to $sum1\n";
  16.         if ($sum1 < $i) {
  17. #               print "$i is a deficient number\n";
  18.         } elsif ($sum1 == $i) {
  19. #               print "$i is a perfect number\n";
  20.         } else {
  21. #               print "$i is an abundant number\n";
  22.                 $abcheck[$i] = 1;
  23.         }
  24. }
  25. $total = 0;
  26. for $i (1..28123) {
  27.         my $is = 0;
  28.         for $j (1..$i) {
  29.                 if ($abcheck[$j] && $abcheck[($i - $j)]) {
  30.                         $is = 1;
  31.                         last;
  32.                 }
  33.         }
  34.         $total += $i if !$is;
  35.         print "Checked $i numbers, running total is $total\n" if ($i % 1000 == 0);
  36. }
  37. print "Sum of integers !(ab+ab): $total\n";
Add Comment
Please, Sign In to add comment