-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
28 lines (22 loc) · 877 Bytes
/
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
#!/usr/bin/ruby
# a(n) is the smallest Fermat pseudoprime to base 2 of the form p * (n*(p-1) + 1), where p is prime.
# The first few terms, are:
# 1194649, 2701, 341, 1387, 4681, 31609, 65281, 14491, 486737, 976873, 10261, 264773, 2757241, 48462301, 742813, 4369, 8534233, 181901, 65077, 489997, 220729, 80581, 107360641, 188057, 9564169, 79854409, 611701, 294271, 489994201, 61219789, 15709, 65301013, 132332201, 2909197, 215749, 123251, 3567481, 429135841, 64148717, 47220367, 2182802689, 257590661, 688213, 22087477, 15479777, 582289, 162690481, 81433591, 55109401, 52072021
func a(n) {
each_prime(1e9, {|p|
var r = (n * (p-1) + 1)
if (r.is_prime && is_pseudoprime(p * r)) {
return p*r
}
})
}
say 50.of { a(_+1) }
__END__
for k in (1..500) {
say a(2**k)
}
__END__
for k in (1..500) {
#say [k, a(k)]
say a(k)
}