carmichael_rad(p-1)==rad(n-1)_db.pl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/perl
  2. # Squarefree composite numbers m such that rad(p-1) = rad(m-1) for every prime p dividing m.
  3. # https://oeis.org/A306479
  4. # First few terms:
  5. # 1729, 46657, 1525781251
  6. # Additional terms (with possible gaps):
  7. # 763546828801, 6031047559681, 184597450297471, 732785991945841, 18641350656000001, 55212580317094201
  8. # See also:
  9. # https://www.primepuzzles.net/puzzles/puzz_969.htm
  10. use 5.020;
  11. use strict;
  12. use warnings;
  13. use experimental qw(signatures);
  14. use Storable;
  15. use POSIX qw(ULONG_MAX);
  16. use Math::GMPz;
  17. use Math::GMPq;
  18. use Math::MPFR;
  19. use ntheory qw(:all);
  20. use Math::Prime::Util::GMP;
  21. use experimental qw(signatures);
  22. use List::Util qw(uniq);
  23. use POSIX qw(ULONG_MAX);
  24. eval { require GDBM_File };
  25. my $cache_db = "cache/factors.db";
  26. dbmopen(my %db, $cache_db, 0444)
  27. or die "Can't create/access database <<$cache_db>>: $!";
  28. sub is_smooth_over_prod ($n, $k) {
  29. state $g = Math::GMPz::Rmpz_init_nobless();
  30. state $t = Math::GMPz::Rmpz_init_nobless();
  31. Math::GMPz::Rmpz_set($t, $n);
  32. Math::GMPz::Rmpz_gcd($g, $t, $k);
  33. while (Math::GMPz::Rmpz_cmp_ui($g, 1) > 0) {
  34. Math::GMPz::Rmpz_remove($t, $t, $g);
  35. return 1 if Math::GMPz::Rmpz_cmp_ui($t, 1) == 0;
  36. Math::GMPz::Rmpz_gcd($g, $t, $g);
  37. }
  38. return 0;
  39. }
  40. my $pm1 = Math::GMPz::Rmpz_init();
  41. my $nm1 = Math::GMPz::Rmpz_init();
  42. my @results;
  43. while (my ($key, $value) = each %db) {
  44. my @factors = split(' ', $value);
  45. Math::GMPz::Rmpz_set_str($nm1, $key, 10);
  46. Math::GMPz::Rmpz_sub_ui($nm1, $nm1, 1);
  47. if (
  48. vecall {
  49. Math::GMPz::Rmpz_set_str($pm1, $_, 10);
  50. Math::GMPz::Rmpz_sub_ui($pm1, $pm1, 1);
  51. is_smooth_over_prod($nm1, $pm1) && is_smooth_over_prod($pm1, $nm1)
  52. }
  53. @factors
  54. ) {
  55. say $key;
  56. }
  57. }
  58. __END__
  59. # Terms > 2^64 (with possible gaps):
  60. 73410179782535364796052059
  61. 5411695603795048325536175041
  62. 95106929041283303531250000001
  63. 31197348228454236739150927323898801
  64. 10558497564199755330631648092537628169160622081
  65. 126217744835361888865876570445244908569293329492211341857910156251
  66. 12148637639549114477071860020956143849622919774718138313293457031251
  67. 5900324689019449887451851353940562090936525912396137121433584769433600000001
  68. 4177392324310826218814556463737392900001943407960199004975124368018024328552246093750000000000000000000000000000000000000000001
  69. 879361831036453821125543949192453243128917237544224266734282340295730119548761964672847363652551337171360809414377113469614340239117201810589199173145474561032406759183371360810887592887141239366187714402476721670165867169914359562716332554707359531428023182618702639403640424644576726719757700564249612631862195373427087696051515417662753403815521084610108301719124456314883210969337514431513915452108414913944611394885081652293989903523033434314819867647387511513090358958380855084361115050053209444024748485904601