count_of_cube-full_numbers.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/perl
  2. # Fast algorithm for counting the number of cube-full numbers <= n.
  3. # A positive integer n is considered cube-full, if for every prime p that divides n, so does p^3.
  4. # See also:
  5. # THE DISTRIBUTION OF CUBE-FULL NUMBERS, by P. SHIU (1990).
  6. # OEIS:
  7. # https://oeis.org/A036966 -- 3-full (or cube-full, or cubefull) numbers: if a prime p divides n then so does p^3.
  8. use 5.020;
  9. use warnings;
  10. use ntheory qw(:all);
  11. use experimental qw(signatures);
  12. sub cubefull_count($n) {
  13. my $total = 0;
  14. for my $a (1 .. rootint($n, 5)) {
  15. is_square_free($a) || next;
  16. for my $b (1 .. rootint(divint($n, powint($a, 5)), 4)) {
  17. gcd($a, $b) == 1 or next;
  18. is_square_free($b) || next;
  19. my $t = mulint(powint($a, 5), powint($b, 4));
  20. $total += rootint(divint($n, $t), 3);
  21. }
  22. }
  23. return $total;
  24. }
  25. foreach my $n (1 .. 20) {
  26. say "C_3(10^$n) = ", cubefull_count(powint(10, $n));
  27. }
  28. __END__
  29. C_3(10^1) = 2
  30. C_3(10^2) = 7
  31. C_3(10^3) = 20
  32. C_3(10^4) = 51
  33. C_3(10^5) = 129
  34. C_3(10^6) = 307
  35. C_3(10^7) = 713
  36. C_3(10^8) = 1645
  37. C_3(10^9) = 3721
  38. C_3(10^10) = 8348
  39. C_3(10^11) = 18589
  40. C_3(10^12) = 41136
  41. C_3(10^13) = 90619
  42. C_3(10^14) = 198767
  43. C_3(10^15) = 434572
  44. C_3(10^16) = 947753
  45. C_3(10^17) = 2062437
  46. C_3(10^18) = 4480253
  47. C_3(10^19) = 9718457
  48. C_3(10^20) = 21055958