prog.pl 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl
  2. # Number of primitive abundant numbers (A071395) < 10^n.
  3. # https://oeis.org/A306986
  4. # Known terms:
  5. # 0, 3, 14, 98, 441, 1734, 8667, 41653, 213087, 1123424
  6. use 5.036;
  7. use ntheory qw(:all);
  8. sub f ($n, $q, $limit) {
  9. #if (($n % 6) == 0 || ($n % 28) == 0 || ($n % 496) == 0 || ($n % 8128) == 0) {
  10. # return 0;
  11. #}
  12. my $count = 0;
  13. my $p = $q;
  14. while (1) {
  15. my $t = $n * $p;
  16. ($t >= $limit) && last;
  17. my $ds = divisor_sum($t);
  18. if ($ds > 2 * $t) {
  19. my $ok = 1;
  20. foreach my $pp (factor_exp($t)) {
  21. my $w = divint($t, $pp->[0]);
  22. if (divisor_sum($w) >= 2 * $w) {
  23. $ok = 0;
  24. last;
  25. }
  26. }
  27. $ok and $count += 1;
  28. }
  29. elsif ($ds < 2*$t) {
  30. $count += f($t, $p, $limit);
  31. }
  32. $p = next_prime($p);
  33. }
  34. return $count;
  35. }
  36. say f(1, 2, powint(10, 4));
  37. say f(1, 2, powint(10, 5));
  38. say f(1, 2, powint(10, 6));
  39. say f(1, 2, powint(10, 11));