unitary_squarefree_divisors.pl 607 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 27 June 2018
  4. # https://github.com/trizen
  5. # Generate the unitary squarefree divisors of a given number.
  6. # See also:
  7. # https://oeis.org/A092261
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use ntheory qw(factor_exp);
  12. sub unitary_squarefree_divisors {
  13. my ($n) = @_;
  14. my @d = (1);
  15. my @pp = map { $_->[0] } grep { $_->[1] == 1 } factor_exp($n);
  16. foreach my $p (@pp) {
  17. push @d, map { $_ * $p } @d;
  18. }
  19. return sort { $a <=> $b } @d;
  20. }
  21. foreach my $n (1 .. 30) {
  22. my @d = unitary_squarefree_divisors($n);
  23. say "a($n) = [@d]";
  24. }