upto(n) = { n = max(n, 10); res = Set([2,3,5,7]); forprime(p = 11, n, if(is(p), res = setunion(res, Set(p)); ) ); res } is(n) = { my(qd = #digits(n), p = partitions(qd)); for(i = 2, #p, perms = permutations(p[i]); for(j = 1, #perms, cn = n; split = List(); for(k = 1, #perms[j], r = cn % 10^perms[j][k]; if(#digits(r) >= perms[j][k], cn \= 10^perms[j][k]; listput(split, r); , next(2); ) ); split = Set(split); if(#split == #perms[j] && #setminus(split, res) == 0, return(0) ) ) ); 1 } permutations(v) = { v = Vec(v); my(res = List()); forperm(v, p, listput(res, Vec(p)); ); res }