bernoulli_denominators_records.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 11 January 2019
  4. # https://github.com/trizen
  5. # Fast program for computing the numbers `n` such that the denominator of Bernoulli(n) is a record.
  6. # OEIS sequences:
  7. # https://oeis.org/A100195
  8. # https://oeis.org/A100194
  9. # See also:
  10. # https://en.wikipedia.org/wiki/Bernoulli_number
  11. # https://mathworld.wolfram.com/BernoulliNumber.html
  12. # https://en.wikipedia.org/wiki/Von_Staudt%E2%80%93Clausen_theorem
  13. use 5.020;
  14. use strict;
  15. use warnings;
  16. use experimental qw(signatures);
  17. use ntheory qw(divisors is_prime vecprod);
  18. sub bernoulli_denominator ($n) { # denominator of the n-th Bernoulli number
  19. return 1 if ($n <= 0);
  20. return 1 if ($n > 1 and $n % 2);
  21. vecprod(map { $_ + 1 } grep { is_prime($_ + 1) } divisors($n));
  22. }
  23. sub records_upto ($n, $callback) {
  24. for (my ($k, $m) = (0, -1) ; $k <= $n ; $k += 2) {
  25. my $sum = 0;
  26. foreach my $d (divisors($k)) {
  27. if (is_prime($d + 1)) {
  28. $sum += log($d + 1);
  29. }
  30. }
  31. if ($sum > $m) {
  32. $m = $sum;
  33. $callback->($k);
  34. }
  35. }
  36. }
  37. records_upto(1e4, sub ($k) { say "B($k) = ", bernoulli_denominator($k) });
  38. __END__
  39. B(0) = 2
  40. B(2) = 6
  41. B(4) = 30
  42. B(6) = 42
  43. B(10) = 66
  44. B(12) = 2730
  45. B(30) = 14322
  46. B(36) = 1919190
  47. B(60) = 56786730
  48. B(72) = 140100870
  49. B(108) = 209191710
  50. B(120) = 2328255930
  51. B(144) = 2381714790
  52. B(180) = 7225713885390
  53. B(240) = 9538864545210
  54. B(360) = 21626561658972270
  55. B(420) = 446617991732222310
  56. B(540) = 115471236091149548610
  57. B(840) = 5145485882746933233510
  58. B(1008) = 14493038256293268734790
  59. B(1080) = 345605409620810598989730
  60. B(1200) = 42107247672297314156359710
  61. B(1260) = 4554106624556364764691012210
  62. B(1620) = 24743736851520275624910204330
  63. B(1680) = 802787680649929796414310788070
  64. B(2016) = 1908324101335116127448341021830
  65. B(2160) = 1324918483651364394207119201026530
  66. B(2520) = 9655818125018463593525930077544596530
  67. B(3360) = 176139196253087613320507734410708168870
  68. B(3780) = 20880040554948303778681975110988542692370
  69. B(5040) = 1520038371910163024272084596792024938493098335890
  70. B(6480) = 2386506545702609292996755910476726098859145077130
  71. B(7560) = 334731403390662540713247087231623394273840419057927010
  72. B(8400) = 30721852291400450355987797336504062619723310330260297070