Project Euler's "Harshad Numbers"
Python 188 bytes

r=range(10)
h=zip(r,r)
w=input()
p=lambda n:all(n%~i for i in range(1,int(n**.5)))%n
while w:
 n,s=h.pop(1)
 for i in r:
    d=s+i;i+=10*n
    if i%d&lt;1:h+=[(i,d)]
    if p(n/s)and p(i):print i;w-=1


This could be made shorter, but my primary concern was efficiency. This code maintains a list of the 'right truncable harshad numbers', as well as the their digital sum, and then uses this list to extend itself by one digit iteratively, allowing only new truncable numbers. I don't see any way to obtain the efficiency required without maintaining such a list. Runtime for n&lt;=50 is less than one second.

A less efficient version, which calculates everthing as it goes (139 bytes, has an acceptable runtime for n&lt;=31):

s=9
w=input()
while w:
 n=s=s+2;x=2;f=0
 while n&gt;9:n/=10;z=sum(map(int,`n`));x-=n%z;f=f or(n/z&lt;3)+n/z
 if(1&lt;&lt;s)%s==(1&lt;&lt;f)%f==x:print s;w-=1