prog.pl 715 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/perl
  2. # Composite numbers (pseudoprimes) n, that are not Carmichael numbers, such that A000670(n) == 1 (mod n).
  3. # https://oeis.org/A289338
  4. # Known terms:
  5. # 169, 885, 2193, 8905, 22713
  6. use 5.010;
  7. use strict;
  8. use warnings;
  9. use ntheory qw(:all);
  10. sub modular_fubini_number {
  11. my ($n, $m) = @_;
  12. my @F = (1);
  13. foreach my $i (1 .. $n) {
  14. foreach my $k (0 .. $i - 1) {
  15. $F[$i] += mulmod($F[$k], binomialmod($i, $i - $k, $m), $m);
  16. }
  17. }
  18. $F[-1] % $n;
  19. }
  20. foreach my $n (1..1e6) {
  21. next if is_prime($n);
  22. next if is_carmichael($n);
  23. if (modular_fubini_number($n, $n) == 1) {
  24. say "Found term: $n";
  25. }
  26. }
  27. __END__
  28. Found term: 169
  29. Found term: 885