lucas-carmichael_numbers_upto.sf 892 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/ruby
  2. # Generate all the Lucas-Carmichael numbers, up to a given bound.
  3. func lucas_carmichael_upto(n) {
  4. var LC = Set()
  5. 3 .. isqrt(n+1)-1 -> each_prime {|p|
  6. var t = p*(p+1)
  7. var lc = (p + t)
  8. loop {
  9. LC << lc if lc.is_lucas_carmichael
  10. lc += t
  11. break if (lc > n)
  12. }
  13. }
  14. return LC.sort
  15. }
  16. var LC = lucas_carmichael_upto(1e6)
  17. say LC
  18. say LC.len
  19. __END__
  20. [399, 935, 2015, 2915, 4991, 5719, 7055, 8855, 12719, 18095, 20705, 20999, 22847, 29315, 31535, 46079, 51359, 60059, 63503, 67199, 73535, 76751, 80189, 81719, 88559, 90287, 104663, 117215, 120581, 147455, 152279, 155819, 162687, 191807, 194327, 196559, 214199, 218735, 230159, 265895, 357599, 388079, 390335, 482143, 588455, 653939, 663679, 676799, 709019, 741311, 760655, 761039, 776567, 798215, 880319, 895679, 913031, 966239, 966779, 973559]
  21. 60