smooth_search.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/perl
  2. # Numbers that are both infinitary and noninfinitary harmonic numbers
  3. # https://oeis.org/A348922
  4. # Known terms:
  5. # 45, 60, 54600, 257040, 1801800, 2789640, 4299750, 47297250, 1707259680, 4093362000
  6. # a(7) > 10^10, if it exists. - Amiram Eldar, Nov 04 2021
  7. # Equivalently, numbers n such that isigma(n) divides n*isigma_0(n) and nisigma(n) divides n*nisigma_0(n).
  8. # Non-squarefree numbers n such that A049417(n) divides n*A037445(n) and A348271(n) divides n*A348341(n).
  9. # See also:
  10. # https://oeis.org/A247077
  11. # The sequence also includes:
  12. # 18779856480
  13. # 44425017000
  14. # 13594055202000
  15. # 27188110404000
  16. # 299069214444000
  17. # 6824215711404000
  18. use 5.020;
  19. use warnings;
  20. use experimental qw(signatures);
  21. use Math::GMPz;
  22. use ntheory qw(:all);
  23. use Math::Sidef qw(isigma isigma0 nisigma nisigma0);
  24. sub check_valuation ($n, $p) {
  25. if ($p == 2) {
  26. return valuation($n, $p) < 10;
  27. }
  28. if ($p == 3) {
  29. return valuation($n, $p) < 12;
  30. }
  31. if ($p == 5) {
  32. return valuation($n, $p) < 7;
  33. }
  34. if ($p == 7) {
  35. return valuation($n, $p) < 7;
  36. }
  37. if ($p == 11) {
  38. return valuation($n, $p) < 3;
  39. }
  40. ($n % $p) != 0;
  41. #valuation($n, $p) < 2;
  42. }
  43. sub smooth_numbers ($limit, $primes) {
  44. my @h = (1);
  45. foreach my $p (@$primes) {
  46. say "Prime: $p";
  47. foreach my $n (@h) {
  48. if ($n * $p <= $limit and check_valuation($n, $p)) {
  49. push @h, $n * $p;
  50. }
  51. }
  52. }
  53. return \@h;
  54. }
  55. sub usigma($n) {
  56. vecprod(map { addint(powint($_->[0], $_->[1]), 1) } factor_exp($n));
  57. }
  58. sub isok ($n) {
  59. is_square_free($n) && return;
  60. (($n*isigma0($n)) % isigma($n)) == 0 or return;
  61. my $t = nisigma($n);
  62. $t == 0 and return;
  63. (($n*nisigma0($n)) % $t) == 0 or return;
  64. return 1;
  65. }
  66. my @smooth_primes;
  67. foreach my $p (@{primes(4801)}) {
  68. if ($p == 2) {
  69. push @smooth_primes, $p;
  70. next;
  71. }
  72. if (
  73. is_smooth($p-1, 5) and
  74. is_smooth($p+1, 7)
  75. ) {
  76. push @smooth_primes, $p;
  77. }
  78. }
  79. my $h = smooth_numbers(~0, \@smooth_primes);
  80. say "\nGenerated: ", scalar(@$h), " numbers";
  81. foreach my $n (@$h) {
  82. if ($n > 1e10 and isok($n)) {
  83. #if (isok($n)) {
  84. say $n;
  85. }
  86. }