-
Notifications
You must be signed in to change notification settings - Fork 0
/
imprimitive_carmichael_coin_change.sf
89 lines (67 loc) · 1.84 KB
/
imprimitive_carmichael_coin_change.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/ruby
# Generate imprimitive Carmichael numbers with n prime factors.
func is_imprimitive(n) {
n.factor.gcd_by { .dec }**2 > lambda(n)
}
var denominations = []
func change(m, pos=0, solution=[]) {
if (solution.len >= 2) {
if (solution[-1] / solution[0] > 40) {
#say '# here'
return nil
}
}
if (solution.len == m) {
with (solution.prod) {|C|
if (C.is_carmichael) {
say C
say "# Imprimitive: #{C}" if is_imprimitive(C)
}
}
return nil
}
if (solution.len > m) {
return nil
}
if (pos > denominations.end) {
return nil;
}
change(m, pos + 1, solution);
change(m, pos + 1, [solution..., denominations[pos]]);
}
func generate_imprimitive(p, m) {
for z in (2..100) {
var arr = []
for k in (1 .. 2.sqrt**z) {
k.is_smooth(5) || next
#next if (2*5 > 40)
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
arr = arr.last(19448)
var count = 0
say "# Combinations: #{t}"
denominations = arr
change(m)
#~ arr.combinations(m, {|*a|
#~ with (a.prod) { |C|
#~ break if (C > 325533792014488126487416882038879701391121)
#~ #break if (C.gpf / C.lpf > 40)
#~ if (C.is_carmichael) {
#~ say C
#~ say "# Imprimitive with p = #{p}: #{C}" if is_imprimitive(C)
#~ }
#~ }
#~ #break if (++count > 1e5)
#~ })
}
}
for p in (primes(73..457)) {
say "# p = #{p}"
generate_imprimitive(p,10)
}