binary_period_pseudoprimes.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/perl
  2. # Composite integers n such that n-1 divided by the binary period of 1/n (=A007733(n)) equals an integral power of 2.
  3. # https://oeis.org/A243050
  4. # Pseudoprimes n such that (n-1)/ord_{n}(2) = 2^k for some k, where ord_{n}(2) = A002326((n-1)/2) is the multiplicative order of 2 mod n. Composite numbers n such that Od(ord_{n}(2)) = Od(n-1), where ord_{n}(2) as above and Od(m) = A000265(m) is the odd part of m. Note that if Od(ord_{n}(2)) = Od(n-1), then ord_{n}(2)|(n-1). - Thomas Ordowski, Mar 13 2019
  5. # Known terms:
  6. # 12801, 348161, 3225601, 104988673, 4294967297, 7816642561, 43796171521, 49413980161, 54745942917121, 51125767490519041, 18314818035992494081, 18446744073709551617
  7. use 5.020;
  8. use strict;
  9. use warnings;
  10. use ntheory qw(:all);
  11. use Math::GMPz;
  12. use experimental qw(signatures);
  13. my %seen;
  14. sub binary_period ($n) {
  15. znorder(2, $n);
  16. }
  17. my $t = Math::GMPz::Rmpz_init();
  18. while (<>) {
  19. next if /^\h*#/;
  20. /\S/ or next;
  21. my $n = (split(' ', $_))[-1];
  22. $n || next;
  23. next if ($n < ~0);
  24. next if length($n) > 30;
  25. (substr($n, -1) & 1) or next; # must be odd
  26. ($n < ((~0) >> 1))
  27. ? Math::GMPz::Rmpz_set_ui($t, $n)
  28. : Math::GMPz::Rmpz_set_str($t, "$n", 10);
  29. my $bp = binary_period($t);
  30. Math::GMPz::Rmpz_sub_ui($t, $t, 1);
  31. Math::GMPz::Rmpz_divisible_ui_p($t, $bp) || next;
  32. Math::GMPz::Rmpz_divexact_ui($t, $t, $bp);
  33. ($t & ($t - 1)) == 0 or next;
  34. say $n if !$seen{$n}++;
  35. }