from_lcm.pl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/usr/bin/perl
  2. use 5.014;
  3. use Math::GMPz;
  4. use List::Util qw(uniq);
  5. use Math::AnyNum qw(is_smooth);
  6. use ntheory qw(forsemiprimes is_square_free forprimes divisor_sum factor forsquarefree random_prime forcomb );
  7. use Math::Prime::Util::GMP qw(mulint is_carmichael vecprod divint sqrtint divisors gcd);
  8. my %seen;
  9. #my $psp = "4788772759754985";
  10. #my $psp = "728017010426459878356936705";
  11. #my $psp = "1370862939340854730059272985";
  12. #my $psp = "45737634436431198836267992527251680040385";
  13. #my $psp = "772459017179480479061611372132330246001039753130436193419524315193543873326133868681083905";
  14. my $psp = "37839385943068863406967633413004957540054532539686888463944906014566240419460804270776358938980032660929917901837033235462145";
  15. #my $psp = "19948738964527549499432007591778845447137932958457586625953063419475941273954097665";
  16. my $lcm = "125627734423978564599155144945225043810910864034881259108837007586928399580842775728597058180217416271320372031434373586786386765336286990826250428173851715663371995737469498702100674661510998130990182331496689289311793735528364441073271";
  17. my @psp_factors = factor($psp);
  18. my @lcm_factors = factor($lcm);
  19. #say "@psp_factors";
  20. @psp_factors = grep{$_ > 1e2} @psp_factors;
  21. my $lp = vecprod(@psp_factors);
  22. say "Sigma = ", divisor_sum($lp, 0);
  23. my @squarefree = grep{gcd($_, $psp) == 1 and is_square_free($_)}3..1e6;
  24. foreach my $k(1..2) {
  25. say "[1] Combination: $k";
  26. forcomb {
  27. if (is_carmichael(vecprod(@lcm_factors[@_], $psp))) {
  28. my $v = vecprod(@lcm_factors[@_], $psp);
  29. if (!$seen{$v}++ and $v ne $psp) {
  30. die "Found: $v";
  31. }
  32. }
  33. }scalar(@lcm_factors), $k;
  34. }
  35. foreach my $k(3..scalar(@psp_factors)) {
  36. say "[2] Combination: $k";
  37. forcomb {
  38. my $p = vecprod(@psp_factors[@_]);
  39. say "Factor: $p";
  40. my $n = divint($psp, $p);
  41. foreach my $v (@squarefree) {
  42. if (is_carmichael(mulint($v, $n))) {
  43. my $v = mulint($v, $n);
  44. if (!$seen{$v}++ and $v ne $psp) {
  45. die "Found: $v";
  46. }
  47. }
  48. }
  49. }scalar(@psp_factors), $k;
  50. }
  51. __END__
  52. if (is_carmichael($psp)) {
  53. say $psp;
  54. }
  55. my $limit = sqrtint($psp);
  56. #my $gcd = 7313655;
  57. #my $gcd = 4381310850645;
  58. #my $gcd = 174766108521378405;
  59. #my $gcd = 77728835801292945;
  60. #my $gcd = 113375180882140665;
  61. #my $gcd = 495088126122885;
  62. #my $gcd = 34498510635;
  63. #my $gcd = "19976310800932286865"; # record
  64. #my $gcd = "7051637712729097263345";
  65. my $gcd = "7524686773155";
  66. my @squarefree;
  67. forprimes {
  68. if ($_ % 2 ==1 and gcd($_, $gcd) == 1 and is_smooth($_-1, 41)) {
  69. push @squarefree, $_;
  70. }
  71. } 1e6;
  72. #~ forsquarefree {
  73. #~ if ($_ % 2 == 1 and $_ > 1 and gcd($_, $psp) == 1) {
  74. #~ push @squarefree, $_;
  75. #~ }
  76. #~ } 1e6;
  77. #push @squarefree, grep{ $_>1 } divisors("6283365899669117794965");
  78. #push @squarefree, grep{ $_>1 } divisors("19976310800932286865");
  79. #push @squarefree, grep{$_>1} divisors("7051637712729097263345");
  80. @squarefree = uniq(@squarefree);
  81. my @factors = factor($psp);
  82. @factors = grep{gcd($gcd, $_) == 1} @factors;
  83. foreach my $k(1..scalar(@factors)>>1) {
  84. say "Combination: $k";
  85. forcomb {
  86. my $d = vecprod(@factors[@_]);
  87. my $n = divint($psp, $d);
  88. for (@squarefree) {
  89. if (is_carmichael(mulint($n, $_))) {
  90. say mulint($n, $_) if !$seen{mulint($n, $_)}++;
  91. }
  92. }
  93. } scalar(@factors), $k;
  94. }
  95. __END__
  96. foreach my $p(divisors($psp)) {
  97. $p > 1 or next;
  98. last if ($p > $limit);
  99. next if (gcd($p, $gcd) > 1);
  100. my $n = divint($psp, $p);
  101. for (@squarefree) {
  102. if (is_pseudoprime(mulint($n, $_), 2)) {
  103. say mulint($n, $_) if !$seen{mulint($n, $_)}++;
  104. }
  105. }
  106. }
  107. __END__
  108. foreach my $n(1..1e6) {
  109. my @copy = @factors;
  110. #$copy[-1] = 3*$n+1;
  111. #$copy[-1] = 2*$n+1;
  112. #$copy[-2] = 4*$n+1;
  113. #$copy[-2] = 2*$n+1;
  114. $copy[rand @copy] = random_prime(1e4);
  115. $copy[rand @copy] = random_prime(1e4);
  116. #$copy[rand @copy] = random_prime(1e4);
  117. #$copy[rand @copy] = 2*int(rand(1e3))+1;
  118. #$copy[-3] = 2*int(rand(1e9))+1;
  119. #$copy[-2] = 3*$n+1;
  120. #$copy[-1] = 1;
  121. #$copy[rand(@copy-9)+8] =
  122. if (is_pseudoprime(vecprod(@copy), 2)) {
  123. if (vecprod(@copy) ne $psp) {
  124. say vecprod(@copy);
  125. }
  126. }
  127. }
  128. exit;
  129. my @psp = qw(
  130. 4788772759754985
  131. 38353281032877674865
  132. 2638294879881771254145
  133. 24773130788808935997465
  134. 39898386437874778336787265
  135. 85866492509341408342261785
  136. 198408004487570768403697185
  137. );
  138. forsquarefree {
  139. #if ($_ % 80 == 9) {
  140. if ($_ % 2 == 1 and $_ > 1) {
  141. foreach my $n(@psp) {
  142. if (is_pseudoprime(mulint($n, $_), 2)) {
  143. say mulint($n, $_);
  144. }
  145. #~ my ($p, $q) = factor($_);
  146. #~ $n = Math::GMPz->new($n);
  147. #~ if ($n % $p == 0) {
  148. #~ if (is_pseudoprime(($n/$p)*$q, 2)) {
  149. #~ say (($n/$p)*$q);
  150. #~ }
  151. #~ }
  152. #~ if ($n % $q == 0) {
  153. #~ if (is_pseudoprime(($n/$q)*$p, 2)) {
  154. #~ say (($n/$q)*$p);
  155. #~ }
  156. #~ }
  157. }
  158. }
  159. } 1e7;
  160. __END__