smooth_search.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/perl
  2. # Unitary harmonic numbers (A006086) that are not unitary arithmetic numbers (A103826).
  3. # https://oeis.org/A353038
  4. # Known terms:
  5. # 90, 40682250, 81364500, 105773850, 423095400, 1798155450, 14385243600
  6. # No other terms are known.
  7. use 5.020;
  8. use warnings;
  9. use experimental qw(signatures);
  10. use Math::GMPz;
  11. use ntheory qw(:all);
  12. sub check_valuation ($n, $p) {
  13. if ($p == 2) {
  14. return valuation($n, $p) < 7;
  15. }
  16. if ($p == 3) {
  17. return valuation($n, $p) < 7;
  18. }
  19. if ($p == 5) {
  20. return valuation($n, $p) < 6;
  21. }
  22. if ($p == 7) {
  23. return valuation($n, $p) < 5;
  24. }
  25. #~ if ($p == 11) {
  26. #~ return valuation($n, $p) < 2;
  27. #~ }
  28. if ($p == 13) {
  29. return valuation($n, $p) < 2;
  30. }
  31. if ($p == 17) {
  32. return valuation($n, $p) < 2;
  33. }
  34. if ($p == 41) {
  35. return valuation($n, $p) < 2;
  36. }
  37. ($n % $p) != 0;
  38. }
  39. sub smooth_numbers ($limit, $primes) {
  40. my @h = (Math::GMPz->new(1));
  41. foreach my $p (@$primes) {
  42. say "Prime: $p";
  43. foreach my $n (@h) {
  44. if ($n * $p <= $limit and check_valuation($n, $p)) {
  45. push @h, $n * $p;
  46. }
  47. }
  48. }
  49. return \@h;
  50. }
  51. #use Math::Sidef qw(usigma usigma0);
  52. sub isok ($n) {
  53. #is_power(Math::GMPz->new(divisor_sum($n)) * euler_phi($n));
  54. # is(n)=my(f=factor(n)); prod(i=1, #f~, f[i, 1]^f[i, 2]+1)%2^#f~==0
  55. my @f = factor_exp($n);
  56. my $usigma = vecprod(map { powint($_->[0], $_->[1]) + 1 } @f);
  57. my $usigma0 = powint(2, scalar(@f));
  58. modint($usigma, $usigma0) == 0
  59. and return;
  60. modint(mulint($n, $usigma0), $usigma) == 0;
  61. #(usigma0($n)*$n) % usigma($n) == 0;
  62. }
  63. my @smooth_primes;
  64. foreach my $p (@{primes(5000)}) {
  65. if ($p == 2) {
  66. push @smooth_primes, $p;
  67. next;
  68. }
  69. my @f1 = factor($p - 1);
  70. my @f2 = factor($p + 1);
  71. if ($f1[-1] <= 5 and $f2[-1] <= 7) {
  72. push @smooth_primes, $p;
  73. }
  74. }
  75. my $h = smooth_numbers(Math::GMPz->new(10)**30, \@smooth_primes);
  76. say "\nFound: ", scalar(@$h), " terms";
  77. my %table;
  78. foreach my $n (@$h) {
  79. $n > 1e12 or next;
  80. $n % 2 == 0 or next;
  81. if (isok($n)) {
  82. say $n;
  83. }
  84. }