A288814alt(n) = { my(p); if(n < 7, [2 * n - 4, 2 + (n % 2)] , p = precprime(n - 2); if(n - p <= 4, [(n - p) * p, p] , my(found = p * A056240alt(n - p)[1], pfound = p, vA = found); while(found / p > n - p && p > 2, p = precprime(p - 1); \\print(p" "found / p" "n - p); vA = A056240alt(n - p)[1] * p; if(vA < found, found = vA; pfound = p; ) \\ found = min(found, A056240(n - p)[1] * p); ); [found, pfound] \\[p * A056240(n - p)[1], p] ) ) } A056240alt(n) = { if(n <= 5, return([n, n - 2 * (n == 4)])); my(p = precprime(n), found = p * (n - p), vA, pfound); if(p == n, return([p, p]) , p = precprime(n - 2); found = p * A056240alt(n - p)[1]; pfound = p; while(found > (n - p) * p && p > 2, p = precprime(p - 1); vA = A056240alt(n - p)[1] * p; if(vA < found, found = vA;\\min(found, A056240alt(n - p)[1] * p); pfound = p; ) ); [found, pfound] ) } a(n) = {my(sp = prime(n + 1), t = 0); sp = nextprime(t * 10^6); forprime(p = sp, , if(p > 10^6 * t, print(10^6 * t); t++); x = A288814alt(p); fmax = x[2]; if (dist(fmax, p, n) == n && x[1] % fmax == 0, y = fmax * A056240alt(p - fmax)[1]; if (y == x[1], return (p); ) ) ) } first(n) = {my(sp = prime(n + 1), res = vector(n), todo = n); forprime(p = 4, , x = A288814alt(p); fmax = x[2]; d = dist(fmax, p, n); if(x[1] % fmax == 0, if(d <= n, y = fmax * A056240alt(p - fmax)[1]; if(y == x[1] && res[d] == 0, res[d] = p; todo--; print(sig(d, p)); if(todo == 0, return(res)); ) , res = concat(res, vector(d - #res)); y = fmax * A056240alt(p - fmax)[1]; if(y == x[1] && res[d] == 0, res[d] = p; print(sig(d, p)); ) ) ) ) } sig(n, an) = {my(res = "a(", p, can); res = concat(res, n); res = concat(res, ") = "); res = concat(res, an); res = concat(res, " ~ "); res = concat(res, n); res = concat(res, "("); can = precprime(an - 1); res = concat(res, an - can); an = can; for(i = 2, n, can = precprime(an - 1); res = concat(res, ", "); res = concat(res, an - can); an = can; ); res = concat(res, "),"); res } \\return distance between primes p1 and p2 with indices i1 and i2; the difference between indices of prime; primepi(p2) - primepi(p1). if p1 > p2 then it's 0. \\ search for a maximum distance of n + 1; if i2 - i1 > n we say it's n + 1. dist(p1, p2, n) = {my(res = 0); forprime(p = p1 + 1, p2, res++; if(res > n, return(n + 1)); ); res }