-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
28 lines (17 loc) · 1.45 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
#!/usr/bin/ruby
# Smallest squarefree palindrome with exactly n distinct prime factors.
# https://oeis.org/A046399
# Known terms:
# 1, 2, 6, 66, 858, 6006, 222222, 22444422, 244868442, 6434774346, 438024420834, 50146955964105, 2415957997595142, 495677121121776594, 22181673755737618122, 8789941164994611499878
# Corrected term:
# a(15) = 5521159517777159511255
# Lower-bounds:
# a(17) > 63005011153853239757078527
#`(
# PARI/GP program:
squarefree_omega_palindromes(A, B, n) = A=max(A, vecprod(primes(n))); (f(m, p, j) = my(list=List()); my(s=sqrtnint(B\m, j)); if(j==1, forprime(q=max(p, ceil(A/m)), s, if(fromdigits(Vecrev(digits(m*q))) == m*q, listput(list, m*q))), forprime(q=p, s, if(q==5 && m%2 == 0, next); list=concat(list, f(m*q, q+1, j-1)))); list); vecsort(Vec(f(1, 2, n)));
a(n) = my(x=vecprod(primes(n)), y=2*x); while(1, my(v=squarefree_omega_palindromes(x, y, n)); if(#v >= 1, return(v[1])); x=y+1; y=2*x); \\ ~~~~
# PARI/GP program (version 2 -- slower):
squarefree_omega_palindromes(A, B, n) = A=max(A, vecprod(primes(n))); (f(m, p, j) = my(list=List()); my(s=sqrtnint(B\m, j)); forprime(q = if(j==1, max(p, ceil(A/m)), p), s, if(q==5 && m%2 == 0, next); my(t=m*q); if(j==1, if(fromdigits(Vecrev(digits(t))) == t, listput(list, t)), list=concat(list, f(t, q+1, j-1)))); list); vecsort(Vec(f(1, 2, n)));
a(n) = my(x=vecprod(primes(n)), y=2*x); while(1, my(v=squarefree_omega_palindromes(x, y, n)); if(#v >= 1, return(v[1])); x=y+1; y=2*x); \\ ~~~~
)