lucas-carmichael_generation_erdos_method.sf 690 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/ruby
  2. # Erdos construction method for Lucas-Carmichael numbers:
  3. # 1. Choose an integer L with many prime factors.
  4. # 2. Let P be the set of primes d-1, where d|L and d-1 does not divide L.
  5. # 3. Find a subset S of P such that prod(S) == -1 (mod L). Then prod(S) is a Lucas-Carmichael number.
  6. var L = 480
  7. var P = L.divisors.map { .dec }.grep { .is_odd && .is_prime }.grep {|p| L%p != 0 }
  8. for k in (3..P.len) {
  9. P.combinations(k, {|*S|
  10. if (S.prod % L == L-1) {
  11. say S.prod
  12. }
  13. })
  14. }
  15. __END__
  16. 51359
  17. 357599
  18. 6023039
  19. 12676799
  20. 16868159
  21. 86450399
  22. 1456083839
  23. 741722399
  24. 10138322879
  25. 3422728799
  26. 674628479
  27. 1458700319
  28. 39472666079
  29. 410636052959
  30. 1087044101759