generate_large_carmichael_with_k_factors.sf 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/ruby
  2. # Generate large Carmichael numbers > 2^64, with exactly k prime factors.
  3. var omega = 4 # must have this many prime factors
  4. var min = 18446744073709551616 # must be greater than this
  5. func a(n) {
  6. var arr = []
  7. var from = 0
  8. var p = prime(n)
  9. for z in (2..35) {
  10. var to = round(sqrt(2)**z)
  11. for k in (from+1 .. to) {
  12. var r = (2*k*p + 1)
  13. if (r.is_prime && (r.dec.gpf == p)) {
  14. #r.inc.is_smooth(p) || next
  15. arr << r
  16. }
  17. }
  18. from = to
  19. if (arr.last(omega).prod < min) {
  20. next
  21. }
  22. while (arr.first(omega).prod < min) {
  23. arr.shift
  24. arr || break
  25. }
  26. # Give up if there are too many combinations to try
  27. break if (binomial(arr.len, omega) > 1e7)
  28. #say arr
  29. arr.combinations(omega, {|*a|
  30. with (a.prod) {|C|
  31. if (C.is_carmichael) {
  32. return C
  33. }
  34. }
  35. })
  36. }
  37. return nil
  38. }
  39. if (ARGV) {
  40. say a(ARGV[0].to_i)
  41. return true
  42. }
  43. for n in (4..100) {
  44. say "# Generating with n = #{n}"
  45. with (a(n)) {|c|
  46. say c
  47. }
  48. }