-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
95 lines (66 loc) · 2.21 KB
/
prog.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
90
91
92
93
94
95
#!/usr/bin/ruby
# The smallest k such that k! + 1 has exactly n prime factors (with multiplicity).
# https://oeis.org/A060250
# Known terms:
# 1, 4, 9, 23, 16, 18, 40, 89
# Lower-bounds:
# a(9) >= 140
include("../../../factordb/auto.sf")
func check_partial_factors(f,n) {
#f.len == f.len || return false
f.sum {|p| p.is_prime ? 1 : 2 } > n && return false
if (f.all_prime) {
if (f.len == n) {
return true
}
return false
}
return true
}
func a(n, from=2) {
for k in (from..Inf) {
var v = (k! + 1)
say "[#{n}] Checking: #{k}"
var tf = v.trial_factor(1e6)
check_partial_factors(tf, n) || next
tf.len.dec + tf.last.ilog(1e6) + 1 >= n || next
tf = v.trial_factor(1e7)
check_partial_factors(tf, n) || next
tf.len.dec + tf.last.ilog(1e7) + 1 >= n || next
if (tf.last > 1e60) {
tf = v.trial_factor(1e8)
check_partial_factors(tf, n) || next
tf.len.dec + tf.last.ilog(1e8) + 1 >= n || next
}
say "Many factors (at least #{tf.len-1 + (tf.last.is_prime ? 1 : 2)} with C#{tf.last.len}): #{v}"
var ff = v.special_factor
check_partial_factors(ff, n) || next
var f = factordb(v)
check_partial_factors(f, n) || next
var f3 = gcd_factors(v, tf + ff + f)
check_partial_factors(f3, n) || next
if ((f3.last > 1e65) && f3.last.is_composite) {
tf = v.trial_factor(1e9)
check_partial_factors(tf, n) || next
tf.len.dec + tf.last.ilog(1e9) + 1 >= n || next
say "Strong candidate..."
f3 = gcd_factors(v, tf + ff + f)
check_partial_factors(f3, n) || next
var pf = f3.grep{.is_prime}
var c = (v / pf.prod)
pf.len + c.ilog(1e9) + 1 >= n || next
say "Factoring C#{c.len}: #{c}"
}
f3 = f3.map{ .is_prime ? _ : factordb(_) }.flat
check_partial_factors(f3, n) || next
f3 = f3.map{ .factor }.flat
check_partial_factors(f3, n) || next
if (f3.len == n) {
return k
}
}
}
#var from = 2
var n = 9
var from = 1
say "a(#{n}) = #{a(n, from)}"