f=lambda n,k=0,m=2,p=1:k/n or-~f(n,k+p%m*(`n`in`m`),m+1,p*m*m) import sys sys.setrecursionlimit(10000) for i in range(1, 21): print '%2d %4d'%(i, f(i))
Standard input is empty
1 11 2 23 3 23 4 149 5 157 6 269 7 73 8 487 9 149 10 1033 11 1129 12 1259 13 1319 14 1483 15 1583 16 1693 17 1777 18 5189 19 1949 20 4201