power_unitary_divisors.pl 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/perl
  2. # Author: Trizen
  3. # Date: 13 September 2023
  4. # https://github.com/trizen
  5. # Generate the k-th power unitary divisors of n.
  6. # See also:
  7. # https://oeis.org/A056624
  8. use 5.036;
  9. use ntheory qw(:all);
  10. sub power_udivisors ($n, $k = 1) {
  11. my @d = (1);
  12. foreach my $pp (factor_exp($n)) {
  13. my ($p, $e) = @$pp;
  14. if ($e % $k == 0) {
  15. my $u = powint($p, $e);
  16. push @d, map { mulint($_, $u) } @d;
  17. }
  18. }
  19. sort { $a <=> $b } @d;
  20. }
  21. say join(', ', power_udivisors(3628800, 1)); # unitary divisors
  22. say join(', ', power_udivisors(3628800, 2)); # square unitary divisors
  23. say join(', ', power_udivisors(3628800, 3)); # cube unitary divisors
  24. say join(', ', power_udivisors(3628800, 4)); # 4th power unitary divisors
  25. __END__
  26. 1, 7, 25, 81, 175, 256, 567, 1792, 2025, 6400, 14175, 20736, 44800, 145152, 518400, 3628800
  27. 1, 25, 81, 256, 2025, 6400, 20736, 518400
  28. 1
  29. 1, 81, 256, 20736