-
Notifications
You must be signed in to change notification settings - Fork 0
/
imprimitive_carmichael.sf
46 lines (35 loc) · 972 Bytes
/
imprimitive_carmichael.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/ruby
# Generate imprimitive Carmichael numbers with n prime factors.
func is_imprimitive(n) {
n.factor.gcd_by { .dec }**2 > lambda(n)
}
func generate_imprimitive(p, m) {
for z in (2..100) {
var arr = []
for k in (1 .. 2.sqrt**z) {
k.is_smooth(5) || next
var r = (2*k*p + 1)
if (r.is_prime && (r.dec.gpf == p)) {
arr << r
}
}
var t = binomial(arr.len, m)
t >= m || next
t < 1e6 || break
var count = 0
say "# Combinations: #{t}"
arr.combinations(m, {|*a|
with (a.prod) { |C|
if (C.is_carmichael) {
say C
say "# Imprimitive with p = #{p}: #{C}" if is_imprimitive(C)
}
}
break if (++count > 1e5)
})
}
}
for p in (primes(100..457)) {
say "# p = #{p}"
generate_imprimitive(p,10)
}