fermat_2^n == 2 (mod n*(n-1)).pl 481 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/perl
  2. # Composite values of n such that 2^n == 2 (mod n*(n-1)).
  3. # https://oeis.org/A217468
  4. use 5.020;
  5. use strict;
  6. use warnings;
  7. use Math::GMPz;
  8. use ntheory qw(:all);
  9. my %seen;
  10. while (<>) {
  11. next if /^\h*#/;
  12. /\S/ or next;
  13. my $n = (split(' ', $_))[-1];
  14. $n || next;
  15. next if $n < ~0;
  16. next if length($n) > 40;
  17. is_pseudoprime($n, 2) || next;
  18. $n = Math::GMPz->new($n);
  19. if (powmod(2, $n, $n * ($n - 1)) == 2) {
  20. say $n;
  21. }
  22. }