uptoqdigits(n) = { maxd = n; res = List(); forprime(p = 2, 7, process(p); ); Set(res) } process(n) = { my(p = partitions(n)); for(i = 2, #p, p[i] = Vec(p[i]); if(#p[i] < maxd, p[i] = concat(vector(maxd - #p[i]), p[i]); ); if(#p[i] <= maxd, processperm(p[i]); ) ) } processperm(v) = { forperm(v, p, c = fromdigits(Vec(p)); if(isprime(c), listput(res, c); ) ) }