-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
59 lines (47 loc) · 1.84 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
#!/usr/bin/ruby
# Smallest m such that the n-th odd prime is the smallest number coprime to m and m+1.
# https://oeis.org/A179675
# First few terms:
# 1, 2, 5, 14, 209, 1364, 714, 62985, 367080, 728364, 64822394, 1306238010, 11182598504, 715041747420, 51913478860880, 454746157008780, 9314160363311804, 560934821217378530, 261062105979210899, 696537082207206753590, 54097844397380813592485, 286495021083846822067820, 80126789479717708423427654
# PARI/GP program:
#`(
a(n) = {my(res = oo, pr = primes(n+1), mp = pr[#pr], mpm1 = mp - 1); v = vector(n, i, [-1, 0]); forvec(x = v, c = lift(chinese(vector(n, i, Mod(x[i], pr[i])))); if(0 < c && c < res, if(c % mp != 0 && c % mp != mpm1, res = c))); res} \\ David A. Corneth, Aug 16 2023
)
# Translation of the PARI/GP program of David A. Corneth (Aug 16 2023):
func a(n) {
var res = Inf
var pr = pn_primes(n+1)
var mp = pr[-1]
n.of { [0, -1] }.cartesian({|*x|
#var c = chinese(x.map_kv {|k,r| Mod(r, pr[k]) }...).lift
var c = Math.chinese(x ~Z pr -> ...)
if (c.is_between(1, res)) {
if (!c.is_congruent(0, mp) && !c.is_congruent(-1, mp)) {
say "a(#{n}) <= #{c}"
res = c
}
}
})
return res
}
say a(19)
__END__
a(19) <= 3401363059422802158514830
a(19) <= 567214303295492728525650
a(19) <= 122403649460760631023060
a(19) <= 114180780729250062077250
a(19) <= 44516558893445889950700
a(19) <= 38318476110235055694960
a(19) <= 34893598609950337767510
a(19) <= 26670729878439768821700
a(19) <= 14168418382219919347530
a(19) <= 13644445161625350582510
a(19) <= 10610530518919318557570
a(19) <= 2851589725365597726510
a(19) <= 2679047929013504398350
a(19) <= 755885136269037417720
a(19) <= 583343339916944089560
a(19) <= 49374994685469676860
a(19) <= 10467246213015082854
a(19) <= 261062105979210899
261062105979210899