test-pseudoprime_search_2.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/perl
  2. use 5.020;
  3. use warnings;
  4. use strict;
  5. use ntheory qw(:all);
  6. use experimental qw(signatures);
  7. use List::Util qw(uniqnum);
  8. use File::Find qw(find);
  9. use Math::GMPz;
  10. use Math::AnyNum qw(prod);
  11. use Math::Prime::Util::GMP qw(is_euler_pseudoprime);
  12. sub is_absolute_euler_pseudoprime ($n) {
  13. is_carmichael($n) and vecall { (($n-1)>>1) % ($_-1) == 0 } factor($n);
  14. }
  15. my $N = 21;
  16. my $P = nth_prime($N);
  17. my $MAX = 10**300;
  18. my @primes_bellow = @{primes($P)};
  19. #~ my $n = 1;
  20. #~ my $P = 2;
  21. my @primes = (2);
  22. sub non_residue {
  23. my ($n) = @_;
  24. foreach my $p (@primes) {
  25. sqrtmod($p, $n) // return $p;
  26. }
  27. return -1;
  28. }
  29. #~ foroddcomposites {
  30. #~ my $k = $_;
  31. #~ #if (powmod($q^((k-1)/2) == -1 and non_residue($k) == $P) {
  32. #~ if (powmod($P, ($k-1)>>1, $k) == $k-1) {
  33. #~ my $q = non_residue($k);
  34. #~ if ($q == $P) {
  35. #~ say $k;
  36. #~ $P = next_prime($P);
  37. #~ push @primes, $P;
  38. #~ exit if $P == 13;
  39. #~ }
  40. #~ }
  41. #~ } 1e9;
  42. #~ __END__
  43. # Are there composite numbers n such that phi(n)2^(n-1) == -1 (mod n) ?
  44. sub isok {
  45. my ($n) = @_;
  46. mulmod(divint(jordan_totient($n,2), jordan_totient($n, 1)), powmod(2, $n-1, $n), $n) == ($n-1);
  47. }
  48. local $| = 1;
  49. #foreach my $n(1..1e9) {
  50. foroddcomposites {
  51. if ( isok($_)) {
  52. print $_, ", ";
  53. }
  54. } 1e9;
  55. exit;
  56. # Carmichael numbers of the form (6*k+1)*(12*k+1)*(18*k+1), where 6*k+1, 12*k+1 and 18*k+1 are all primes.
  57. # Carmichael numbers of the form C = (30n-p)*(60n-(2p+1))*(90n-(3p+2)), where n is a natural number and p, 2p+1, 3p+2 are all three prime numbers.
  58. # Numbers of the form: (6*m + 1) * (12*m + 1) * Product_{i=1..k-2} (9 * 2^i * m + 1), where k >= 3, with the condition that each of the factors is prime and that m is divisible by 2^(k-4).
  59. #~ foreach my $k(1..1e7) {
  60. #~ my $x = 6*$k+1;
  61. #~ my $y = 12*$k + 1;
  62. #~ my $z = 18*$k+1;
  63. #~ #my $w = 9 * 2**2 * $k+1;
  64. #~ if (is_prime($x) and is_prime($y) and is_prime($z)
  65. #~ #and is_prime($w)
  66. #~ ) {
  67. #~ my $n = prod($x, $y, $z);
  68. #~ if (isok($n)) {
  69. #~ say "[$k] -> a($N) <= $n";
  70. #~ }
  71. #~ }
  72. #~ }
  73. #~ __END__
  74. #~ #foreach my $k(1..1e6) {
  75. #~ $| = 1;
  76. #~ #for (my $k = 3; $k <= 1e9; $k += 2) {
  77. #~ foroddcomposites {
  78. #~ my $k = $_;
  79. #~ #if (not is_prime($k) and isok($k)) {
  80. #~ if (isok($k)) {
  81. #~ print($k, ", ");
  82. #~ if (not isok_stronger($k)) {
  83. #~ die "Counter-example: $k";
  84. #~ }
  85. #~ }
  86. #~ } 1e9;
  87. #~ __END__
  88. my %seen;
  89. sub process_file {
  90. my ($file) = @_;
  91. open my $fh, '<', $file;
  92. while (<$fh>) {
  93. next if /^\h*#/;
  94. /\S/ or next;
  95. my $n = (split(' ', $_))[-1];
  96. $n || next;
  97. #if ($n > $MAX or $n <= 2) {
  98. # next;
  99. #}
  100. if (length($n) > 30) {
  101. next;
  102. }
  103. #~ if ($n < 14469841 or $n > $MAX) {
  104. #~ next;
  105. #~ }
  106. #~ if ($n < ~0) {
  107. #~ next;
  108. #~ }
  109. #if ($n < 619440406020833) {
  110. # next;
  111. #}
  112. #if ($n < 1.7 * 10**16) {
  113. #~ next;
  114. #~ }
  115. #~ if ($n > ~0) {
  116. #~ next;
  117. #~ }
  118. #~ if ($n > 10**8) {
  119. #~ next;
  120. #~ }
  121. #if ($n > ~0) {
  122. #if (length($n) > 30) {
  123. # next;
  124. #}
  125. next if $seen{$n}++;
  126. if ($n > ~0) {
  127. $n = Math::GMPz->new("$n");
  128. }
  129. #next if is_prime($n);
  130. #if (isok_b($n)) {
  131. # if (not is_absolute_euler_pseudoprime($n) and isok_12_may($n) ) {
  132. # say "Testing: $n";
  133. #if (isok_12_may($n) and not is_carmichael($n)) {#not isok_12_may_stronger($n)) {
  134. # if (isok_12_may($n) and not isok_12_may_stronger($n)) {# not is_carmichael($n)) {
  135. if (isok($n)) {
  136. #say "Counter-example: $n";
  137. say "Found: $n";
  138. #~ if ($n < $MAX) {
  139. #~ $MAX = $n;
  140. #~ }
  141. #last if ($n > 15851273401);
  142. #$MAX = $n;
  143. # if (not isok_stronger($n)) {
  144. # die "Counter-example: $n";
  145. # }
  146. #~ if ($n < $MAX) {
  147. #~ $MAX = $n;
  148. #~ say "New record: $n";
  149. #~ }
  150. }
  151. }
  152. close $fh;
  153. }
  154. my $psp = "/home/swampyx/Other/Programare/experimental-projects/pseudoprimes/oeis-pseudoprimes";
  155. find({
  156. wanted => sub {
  157. if (/\.txt\z/) {
  158. #say "Processing $_";
  159. process_file($_);
  160. }
  161. },
  162. no_chdir => 1,
  163. } => $psp);