smooth_search.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/perl
  2. # Numbers that are both unitary and nonunitary harmonic numbers.
  3. # https://oeis.org/A348923
  4. # Known terms:
  5. # 45, 60, 3780, 64260, 3112200, 6320160
  6. # a(7) > 10^12, if it exists. - Amiram Eldar, Nov 04 2021
  7. # Equivalently, numbers n such that usigma(n) divides n*usigma_0(n) and sigma(n) - usigma(n) divides n*(sigma_0(n) - usigma_0(n)).
  8. # Non-squarefree numbers n such that A034448(n) divides n*A034444(n) and A048146(n) divides n*A048105(n).
  9. # See also:
  10. # https://oeis.org/A247077
  11. # No other terms are known...
  12. use 5.020;
  13. use warnings;
  14. use experimental qw(signatures);
  15. use Math::GMPz;
  16. use ntheory qw(:all);
  17. sub check_valuation ($n, $p) {
  18. if ($p == 2) {
  19. return valuation($n, $p) < 20;
  20. }
  21. if ($p == 3) {
  22. return valuation($n, $p) < 5;
  23. }
  24. if ($p == 5) {
  25. return valuation($n, $p) < 4;
  26. }
  27. if ($p == 7) {
  28. return valuation($n, $p) < 3;
  29. }
  30. ($n % $p) != 0;
  31. #valuation($n, $p) < 2;
  32. }
  33. sub smooth_numbers ($limit, $primes) {
  34. my @h = (1);
  35. foreach my $p (@$primes) {
  36. say "Prime: $p";
  37. foreach my $n (@h) {
  38. if ($n * $p <= $limit and check_valuation($n, $p)) {
  39. push @h, $n * $p;
  40. }
  41. }
  42. }
  43. return \@h;
  44. }
  45. sub usigma($n) {
  46. vecprod(map { addint(powint($_->[0], $_->[1]), 1) } factor_exp($n));
  47. }
  48. sub isok ($n) {
  49. is_square_free($n) && return;
  50. my $usigma = usigma($n);
  51. my $usigma0 = powint(2, prime_omega($n));
  52. modint(mulint($n, $usigma0), $usigma) == 0 or return;
  53. my $t = subint(divisor_sum($n), $usigma);
  54. $t == 0 and return;
  55. modint(mulint($n, subint(divisor_sum($n, 0), $usigma0)), $t) == 0 or return;
  56. return 1;
  57. }
  58. my @smooth_primes;
  59. foreach my $p (@{primes(4801)}) {
  60. if ($p == 2) {
  61. push @smooth_primes, $p;
  62. next;
  63. }
  64. if (
  65. is_smooth($p-1, 5) and
  66. is_smooth($p+1, 7)
  67. ) {
  68. push @smooth_primes, $p;
  69. }
  70. }
  71. my $h = smooth_numbers(~0, \@smooth_primes);
  72. say "\nGenerated: ", scalar(@$h), " numbers";
  73. foreach my $n (@$h) {
  74. if ($n > 1e12 and isok($n)) {
  75. #if (isok($n)) {
  76. say $n;
  77. }
  78. }