multi_resta.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/perl
  2. # Integers k such that k is equal to the sum of the nonprime proper divisors of k.
  3. # https://oeis.org/A331805
  4. # 9*10^12 < a(4) <= 72872313094554244192 = 2^5 * 109 * 151 * 65837 * 2101546957. - Giovanni Resta, Jan 28 2020
  5. # Notice that:
  6. # 65837 = 2^2 * 109 * 151 + 1
  7. # sigma(2^5 * 109 * 151 * 65837) / 2101546957 =~ 33.00003145254488 =~ 2^5 + 1
  8. # Also:
  9. # log_3(72872313094554244192) =~ 41.6300098 (coincidence?)
  10. use 5.014;
  11. use ntheory qw(:all);
  12. use List::Util qw(uniq);
  13. use Math::GMPz;
  14. #use Math::AnyNum qw(:overload);
  15. sub prime_sigma {
  16. my ($n) = @_;
  17. vecsum(uniq(factor($n)));
  18. }
  19. sub isok {
  20. my ($n) = @_;
  21. divisor_sum($n) - $n - prime_sigma($n) == $n;
  22. }
  23. #say isok(72872313094554244192);
  24. forsquarefree {
  25. my $r = $_;
  26. foreach my $k (1..4) {
  27. my $t = (1 << $k) * $r + 1;
  28. is_prime($t) || next;
  29. foreach my $j ($k .. 2 * $k + 1) {
  30. my $v = (1 << $j) * $r * $t;
  31. if ($v > ~0) {
  32. $v = Math::GMPz::Rmpz_init_set_ui($r);
  33. Math::GMPz::Rmpz_mul_ui($v, $v, $t);
  34. Math::GMPz::Rmpz_mul_2exp($v, $v, $j);
  35. }
  36. my $s = divisor_sum($v);
  37. my $ratio = "$s"/"$v";
  38. $ratio < 2 or next;
  39. $ratio > 1.9999 or next;
  40. #"$s" / "$v" > (2 - 1 / "$v"**(2 / 3)) or next;
  41. #"$s"/"$v" > 1.999999999 or next;
  42. my $ps = prime_sigma($r);
  43. say "$r, $v, [$k, $j] -> ", $s - (2 + $t + $ps), " with $ratio";
  44. foreach my $p (factor($s - (2 + $t + $ps))) {
  45. my $u = ($v * $p);
  46. if (!ref($u) and $u > ~0) {
  47. $u = Math::GMPz->new($v) * $p;
  48. }
  49. if ($u > 1e13 && isok($u)) {
  50. say "\nFound: $u\n";
  51. if ("$u" ne "72872313094554244192") {
  52. die "New term: $u";
  53. }
  54. }
  55. }
  56. }
  57. }
  58. } 1,1e9;