chernick-carmichael_polynomials.pl 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 16 February 2020
  4. # https://github.com/trizen
  5. # Generate the polynomials for the extended Chernick-Carmichael numbers with n prime factors.
  6. # OEIS sequence:
  7. # https://oeis.org/A318646 -- The least Chernick's "universal form" Carmichael number with n prime factors.
  8. # See also:
  9. # https://oeis.org/wiki/Carmichael_numbers
  10. # https://www.ams.org/journals/bull/1939-45-04/S0002-9904-1939-06953-X/home.html
  11. # The ratios sum([C(n+1)]) / sum([C(n)]), are given by the OEIS sequence A083705,
  12. # https://oeis.org/A083705
  13. # where sum([C(n)]) is the sum of the coefficients of the n-th Chernick-Carmichael polynomial,
  14. use 5.020;
  15. use warnings;
  16. use experimental qw(signatures);
  17. use Math::Polynomial;
  18. use List::Util qw(reduce);
  19. use Math::AnyNum qw(:overload sum prod);
  20. sub chernick_carmichael_factors ($n) {
  21. reduce { $a * $b } (
  22. Math::Polynomial->new(1, 6), Math::Polynomial->new(1, 12),
  23. map { Math::Polynomial->new(1, 9 << $_) } 1 .. $n - 2
  24. );
  25. }
  26. say "=> Polynomials:";
  27. foreach my $n (3 .. 10) {
  28. say "C($n) = ", chernick_carmichael_factors($n);
  29. }
  30. say "\n=> Sum of coefficients:";
  31. foreach my $n (3 .. 10) {
  32. say "sum([C($n)]) = ", sum(chernick_carmichael_factors($n)->coeff);
  33. }
  34. say "\n=> Product of coefficients:";
  35. foreach my $n (3 .. 10) {
  36. say "prod([C($n)]) = ", prod(chernick_carmichael_factors($n)->coeff);
  37. }
  38. __END__
  39. => Polynomials:
  40. C(3) = (1296 x^3 + 396 x^2 + 36 x + 1)
  41. C(4) = (46656 x^4 + 15552 x^3 + 1692 x^2 + 72 x + 1)
  42. C(5) = (3359232 x^5 + 1166400 x^4 + 137376 x^3 + 6876 x^2 + 144 x + 1)
  43. C(6) = (483729408 x^6 + 171320832 x^5 + 20948544 x^4 + 1127520 x^3 + 27612 x^2 + 288 x + 1)
  44. C(7) = (139314069504 x^7 + 49824129024 x^6 + 6204501504 x^5 + 345674304 x^4 + 9079776 x^3 + 110556 x^2 + 576 x + 1)
  45. C(8) = (80244904034304 x^8 + 28838012387328 x^7 + 3623616995328 x^6 + 205312900608 x^5 + 5575625280 x^4 + 72760032 x^3 + 442332 x^2 + 1152 x + 1)
  46. C(9) = (92442129447518208 x^9 + 33301635174236160 x^8 + 4203244791005184 x^7 + 240144078495744 x^6 + 6628433223168 x^5 + 89395182144 x^4 + 582326496 x^3 + 1769436 x^2 + 2304 x + 1)
  47. C(10) = (212986666247081951232 x^10 + 76819409570887630848 x^9 + 9717577633650180096 x^8 + 557495201645199360 x^7 + 15512054224674816 x^6 + 212594932882944 x^5 + 1431075428928 x^4 + 4659107040 x^3 + 7077852 x^2 + 4608 x + 1)
  48. => Sum of coefficients:
  49. sum([C(3)]) = 1729
  50. sum([C(4)]) = 63973
  51. sum([C(5)]) = 4670029
  52. sum([C(6)]) = 677154205
  53. sum([C(7)]) = 195697565245
  54. sum([C(8)]) = 112917495146365
  55. sum([C(9)]) = 130193871903758845
  56. sum([C(10)]) = 300096874738164137725
  57. => Product of coefficients:
  58. prod([C(3)]) = 18475776
  59. prod([C(4)]) = 88394777100288
  60. prod([C(5)]) = 532962603198108087091200
  61. prod([C(6)]) = 15566146576014516344690540671590727680
  62. prod([C(7)]) = 8607729694274768470180293645913878477204634698636066816
  63. prod([C(8)]) = 355900510244809815184693136856938085570466396628469022965807673827511731486720
  64. prod([C(9)]) = 4371202733642080997695663760838408017640388301504244892063249651693811055142174806499598124164351828951040
  65. prod([C(10)]) = 63565858610074701536163462529753569644918704418351291678528316792385645865008717295355264067966620308836237036012393969126437841481288908800