x.pl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/perl
  2. # Numbers with exactly five distinct exponents in their prime factorization, or five distinct parts in their prime signature.
  3. # https://oeis.org/A323056
  4. # Bellow 10^10
  5. #~ Found prime p=631.
  6. #~ Found 90397884 candidates.
  7. #~ 2613
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use List::Util qw(uniq);
  12. use ntheory qw(primes factor_exp next_prime);
  13. # Generate all the p-smooth numbers that are the product of <= 5 distinct primes bellow a given limit.
  14. sub smooth_numbers {
  15. my ($limit, $primes) = @_;
  16. my @h = (1);
  17. foreach my $p (@$primes) {
  18. foreach my $n (@h) {
  19. if ($n * $p <= $limit and scalar(factor_exp($n * $p)) <= 5) {
  20. push @h, $n * $p;
  21. }
  22. }
  23. }
  24. return \@h;
  25. }
  26. # First, we find the smallest prime p such that:
  27. # p * 2^5 * 3^4 * 5^3 * 7^2 > limit
  28. sub find_largest_prime {
  29. my ($limit) = @_;
  30. for (my $p = 2 ; ; $p = next_prime($p)) {
  31. if ($p * 2**5 * 3**4 * 5**3 * 7**2 > $limit) {
  32. return $p;
  33. }
  34. }
  35. }
  36. # For limit=10^9, we have p = 67
  37. my $limit = 10**9;
  38. my $p = find_largest_prime($limit);
  39. say "Found prime p=$p.";
  40. my $h = smooth_numbers($limit, primes($p));
  41. say "Found ", scalar(@$h), " candidates.";
  42. foreach my $n (sort { $a <=> $b } @$h) {
  43. if (scalar(uniq(map { $_->[1] } factor_exp($n))) == 5) {
  44. print "$n, ";
  45. }
  46. }
  47. __END__
  48. 174636000, 206388000, 244490400, 261954000, 269892000, 274428000, 288943200, 291060000, 301644000, 309582000, 343980000, 349272000, 365148000, 366735600, 377848800, 383292000, 404838000, 411642000, 412776000, 422301600, 433414800, 449820000, 452466000, 457380000, 460404000, 488980800, 492156000, 502740000, 509652000, 511207200, 537878880, 539784000, 547722000, 548856000, 566773200, 570477600, 574938000, 577886400, 582120000, 587412000, 602316000, 603288000, 603741600, 608580000, 633452400, 638820000, 644565600, 650916000, 654885000, 655452000, 666468000, 674200800, 679140000, 682668000, 687960000, 689018400, 690606000, 698544000, 727650000, 730296000, 738234000, 744876000, 746172000, 751252320, 755697600, 764478000, 766584000, 766810800, 767340000, 773955000, 785862000, 802620000, 806818320, 818748000, 820260000, 822376800, 825552000, 841428000, 844603200, 845238240, 849420000, 859950000, 881118000, 881647200, 899640000, 901692000, 903474000, 905612400, 911282400, 914760000, 920808000, 928746000, 930852000, 936684000, 950796000, 955735200, 966848400, 968436000, 976374000, 977961600, 979020000, 983178000, 984312000, 985370400, 996559200, 999702000