smooth_upper-bounds.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/perl
  2. # a(n) is the smallest k such that psi(k) and phi(k) have same distinct prime factors when k is the product of n distinct primes (psi(k) = A001615(k) and phi(k) = A000010(k)), or 0 if no such k exists.
  3. # https://oeis.org/A291138
  4. # Known terms:
  5. # 3, 14, 42, 210, 3570, 43890, 746130, 14804790, 281291010, 8720021310
  6. use 5.020;
  7. use warnings;
  8. use experimental qw(signatures);
  9. use ntheory qw(:all);
  10. use List::Util qw(uniq);
  11. sub check_valuation ($n, $p) {
  12. ($n % $p) != 0;
  13. }
  14. sub smooth_numbers ($limit, $primes) {
  15. my @h = (1);
  16. foreach my $p (@$primes) {
  17. say "Prime: $p";
  18. foreach my $n (@h) {
  19. if ($n * $p <= $limit and check_valuation($n, $p)) {
  20. push @h, $n * $p;
  21. }
  22. }
  23. }
  24. return \@h;
  25. }
  26. sub isok ($n) {
  27. my @factors = factor($n);
  28. my $psi = vecprod(uniq(factor(lcm(map{$_+1}@factors))));
  29. my $phi = vecprod(uniq(factor(lcm(map{$_-1}@factors))));
  30. if ($psi == $phi) {
  31. return scalar(@factors);
  32. }
  33. return 0;
  34. }
  35. my @smooth_primes;
  36. foreach my $p (@{primes(4801)}) {
  37. if ($p == 2) {
  38. push @smooth_primes, $p;
  39. next;
  40. }
  41. my @f1 = factor($p - 1);
  42. my @f2 = factor($p + 1);
  43. if ($f1[-1] <= 11 and $f2[-1] <= 11) {
  44. push @smooth_primes, $p;
  45. }
  46. }
  47. my $h = smooth_numbers(~0, \@smooth_primes);
  48. say "\nFound: ", scalar(@$h), " terms";
  49. my %table;
  50. foreach my $n (@$h) {
  51. my $p = isok($n);
  52. if ($p >= 11) {
  53. if (not exists $table{$p} or $n < $table{$p}) {
  54. $table{$p} = $n;
  55. say "a($p) = $n -> ", join(' * ', map { "$_->[0]^$_->[1]" } factor_exp($n));
  56. }
  57. }
  58. }
  59. say '';
  60. foreach my $k (sort { $a <=> $b } keys %table) {
  61. say "a($k) <= ", $table{$k};
  62. }
  63. __END__
  64. # Upper-bounds:
  65. a(11) <= 278196808890
  66. a(12) <= 8624101075590
  67. a(13) <= 353588144099190
  68. a(14) <= 25104758231042490
  69. a(15) <= 2234323482562781610