carmichael_numbers_random.pl 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/perl
  2. # Generate random Carmichael numbers of the form (k+1)*(2*k+1)*(3*k+1), where k+1, 2*k+1 and 3*k+1 are all primes.
  3. # See also:
  4. # https://oeis.org/A033502 -- Carmichael numbers of the form (6*k+1)*(12*k+1)*(18*k+1)
  5. # https://oeis.org/A255441 -- Carmichael numbers of the form (60k+41)(90k+61)(150k+101)
  6. # https://oeis.org/A255514 -- Carmichael numbers of the form (24*k+13)*(72*k+37)*(192*k+97)
  7. # https://oeis.org/A182085 -- Carmichael numbers of the form (30k+7)*(60k+13)*(150k+31)
  8. # https://oeis.org/A182088 -- Carmichael numbers of the form (30n-29)*(60n-59)*(90n-89)*(180n-179)
  9. # https://oeis.org/A182132 -- Carmichael numbers of the form (30n-7)*(90n-23)*(300n-79)
  10. # https://oeis.org/A182133 -- Carmichael numbers of the form (30n-17)*(90n-53)*(150n-89)
  11. # https://oeis.org/A182416 -- Carmichael numbers of the form (60k+13)*(180k+37)*(300k+61)
  12. use 5.020;
  13. use warnings;
  14. use experimental qw(signatures);
  15. use Math::GMPz;
  16. use Math::Prime::Util::GMP qw(is_prob_prime vecprod random_ndigit_prime);
  17. sub random_carmichael_number ($n = 20) {
  18. $n = 2 if ($n <= 1);
  19. while (1) {
  20. my $p = Math::GMPz::Rmpz_init_set_str(random_ndigit_prime($n), 10);
  21. my $k = ($p - 1);
  22. is_prob_prime(2*$k + 1) && is_prob_prime(3*$k + 1) or next;
  23. return ($p, 2*$k + 1, 3*$k + 1);
  24. }
  25. }
  26. foreach my $n (2 .. 20) {
  27. my @factors = random_carmichael_number($n);
  28. my $carmichael = vecprod(@factors);
  29. say "$carmichael = ", join(' * ', @factors);
  30. }
  31. __END__
  32. 294409 = 37 * 73 * 109
  33. 56052361 = 211 * 421 * 631
  34. 71171308081 = 2281 * 4561 * 6841
  35. 129140929242289 = 27817 * 55633 * 83449
  36. 472631192510407921 = 428671 * 857341 * 1286011
  37. 27572283826108082569 = 1662547 * 3325093 * 4987639
  38. 345721500688805466654601 = 38624101 * 77248201 * 115872301
  39. 130699973774636844248473489 = 279281017 * 558562033 * 837843049
  40. 27673744421175202436239020169 = 1664583397 * 3329166793 * 4993750189
  41. 328972311969416805526009802207569 = 37990006297 * 75980012593 * 113970018889
  42. 2154063839571860482226489311256938129 = 710726387407 * 1421452774813 * 2132179162219
  43. 570115866940668362539466801338334994649 = 4563211789627 * 9126423579253 * 13689635368879
  44. 1782421577597012564570834220077888509756969 = 66724663694947 * 133449327389893 * 200173991084839
  45. 52582793280275762357474570728765725923205529 = 206172530234557 * 412345060469113 * 618517590703669
  46. 278521214364869103131896930517366707497856421161 = 3593925000970261 * 7187850001940521 * 10781775002910781
  47. 1033219900193456185960963387986087314925660018643009 = 55634881918514887 * 111269763837029773 * 166904645755544659
  48. 1081644507889807242059050179401322818854661656619742361 = 564908053691846461 * 1129816107383692921 * 1694724161075539381
  49. 341413647754278719970853443358101430514668165478272427161 = 3846300480078170011 * 7692600960156340021 * 11538901440234510031
  50. 6271289738172907436343660234664403558286290715038000756209 = 10148500369293939337 * 20297000738587878673 * 30445501107881818009