explore(p, r) = { if (r==0, if (isprime(p), nb++; ), for (d=1, min(9, r), explore(10*p+d, r-d); ); ); } a(n) = { nb = 0; if (n==3 || n%3, explore(0, n); ); nb } for (n=1, 100, print (n " " a(n))) quit