iterative_difference_of_central_divisors_to_reach_zero.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 22 March 2019
  4. # https://github.com/trizen
  5. # Let f(n) be the difference between the least divisor of n that is >= sqrt(n) and the greatest divisor of n that is <= sqrt(n).
  6. # Let g(n) be the number of iterations of f(n) required to reach zero.
  7. # Then a(n) is the smallest integer k of the form x*(x + a(n-1)), such that g(k) = n, for some positive integer x, with a(0) = 0.
  8. # This sequence provides upper-bounds for:
  9. # https://oeis.org/A324921
  10. # Example:
  11. # a(30) = 940055257114567466733218694 = 42 * (42 + 205 * (205 + 68 * (68 + 9 * (9 + 56 * (56 + 53 * (53 + 14 * (14 + 5 * (5 + 34 * (34 + 73 * (73 + 6 * (6 + 43 * (43 + 8 * (8 + 3 * (3 + 10 * (10 + 9 * (9 + 4 * (4 + 7 * (7 + 12 * (12 + 5 * (5 + 2 * (2 + 1 * (1 + 2 * (2 + 3 * (3 + 2 * (2 + 1 * (1 + 2 * (2 + 1 * (1 + 1 * (1 + 1 * (1 + 0))))))))))))))))))))))))))))))
  12. # OEIS sequences:
  13. # https://oeis.org/A324921 -- Index of first occurrence of n in A324920.
  14. # https://oeis.org/A056737 -- Minimum nonnegative integer m such that n = k*(k+m) for some positive integer k.
  15. # https://oeis.org/A324920 -- a(n) is the number of iterations of the integer splitting function (A056737) necessary to reach zero.
  16. use 5.020;
  17. use warnings;
  18. use Math::GMPz;
  19. use ntheory qw(:all);
  20. use experimental qw(signatures);
  21. sub f($n) {
  22. if (is_square($n)) {
  23. 0;
  24. }
  25. else {
  26. my @d = divisors($n);
  27. Math::GMPz->new($d[(1 + $#d) >> 1]) - $d[($#d) >> 1];
  28. }
  29. }
  30. sub g($n) {
  31. my $t = f($n);
  32. my $count = 1;
  33. while ($t) {
  34. $t = f($t);
  35. ++$count;
  36. }
  37. $count;
  38. }
  39. my $n = Math::GMPz->new(0);
  40. for my $j (1 .. 30) {
  41. for (my $x = 1 ; ; ++$x) {
  42. my $k = $x * ($n + $x);
  43. my $t = g($k);
  44. if ($t == $j) {
  45. $n = $k;
  46. say "a($j) = $k";
  47. last;
  48. }
  49. }
  50. }
  51. __END__
  52. a(1) = 1
  53. a(2) = 2
  54. a(3) = 3
  55. a(4) = 10
  56. a(5) = 11
  57. a(6) = 26
  58. a(7) = 87
  59. a(8) = 178
  60. a(9) = 179
  61. a(10) = 362
  62. a(11) = 1835
  63. a(12) = 22164
  64. a(13) = 155197
  65. a(14) = 620804
  66. a(15) = 5587317
  67. a(16) = 55873270
  68. a(17) = 167619819
  69. a(18) = 1340958616
  70. a(19) = 57661222337
  71. a(20) = 345967334058
  72. a(21) = 25255615391563
  73. a(22) = 858690923314298
  74. a(23) = 4293454616571515
  75. a(24) = 60108364632001406
  76. a(25) = 3185743325496077327
  77. a(26) = 178401626227780333448
  78. a(27) = 1605614636050023001113
  79. a(28) = 109181795251401564080308
  80. a(29) = 22382268026537320636505165
  81. a(30) = 940055257114567466733218694
  82. a(31) = 102466023025487853873920849527
  83. a(32) = 3688776828917562739461150584268
  84. a(33) = 217637832906136201628207884475293
  85. a(34) = 10011340313682265274897562685865594
  86. a(35) = 830941246035628017816497702926851191
  87. a(36) = 74784712143206521603484793263416615290
  88. a(37) = 9946366715046467373263477504034409851259
  89. a(38) = 1233349472665761954284671210500266821571492
  90. a(39) = 11100145253991857588562040894502401394143509
  91. a(40) = 155402033555886006239868572523033619518009322
  92. a(41) = 6060679308679554243354874328398311161202365079
  93. a(42) = 12121358617359108486709748656796622322404730162
  94. a(43) = 1321228089292142825051362603590831833142115599539
  95. a(44) = 295955092001439992811505223204346330623833894346912
  96. a(45) = 3255506012015839920926557455247809636862172837816153
  97. a(46) = 97665180360475197627796723657434289105865185134485490
  98. a(47) = 8887531412803242984129501852826520308633731847238187871
  99. a(48) = 106650376953638915809554022233918243703604782166858254596
  100. a(49) = 23143131798939644730673222824760258883682237730208241294421
  101. a(50) = 2036595598306688736299243608578902781764036920258325233916792