fork(3) download
  1. 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)
  2.  
  3. import sys
  4. sys.setrecursionlimit(10000)
  5.  
  6. for i in range(1, 21):
  7. print '%2d %4d'%(i, f(i))
Success #stdin #stdout 1.38s 10696KB
stdin
Standard input is empty
stdout
 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