How many prime numbers contain strictly increasing digits?

368 Views Asked by At

This was posed as an estimation problem - I'd be interested in both more accurate approximate methods (than my underestimate of 74 in the answer below) and a check of my exact answer (100, already verified in the comment section).

1

There are 1 best solutions below

3
On

I originally estimated that there would be $74$ such numbers. This was based on counting the primes with $1,2$ and $9$ digits, and for $k=3,4,…8$, observing that there are $9 \choose k$ integers with $k$ strictly increasing digits and that each has roughly a $\frac1{\log x}$ probability of being prime, which I further rounded to $\frac{1}{2.3(k-1)}$. This gave roughly $4+11+17+18+14+7+2+1+0=74$.

I believe that there are exactly $100$ such numbers. This is based on the matlab code below. Sorting again by number of digits, this was $4+11+20+26+20+13+4+2+0$—the biggest error with my approximate model seems to be in $4–6$-digit numbers.

n=0;
for i=1:9
    if isprime(i)==1
        n=n+1;
    end
    for j=i+1:9
        if isprime(10*i+j)==1
            n=n+1;
        end
        for k=j+1:9
            if isprime(100*i+10*j+k)==1
                n=n+1;
            end
            for l=k+1:9
                if isprime(1000*i+100*j+10*k+l)==1
                    n=n+1;
                end
                for m=l+1:9
                    if isprime(10000*i+1000*j+100*k+10*l+m)==1
                        n=n+1;
                    end
                    for o=m+1:9
                        if isprime(100000*i+10000*j+1000*k+100*l+10*m+o)==1
                            n=n+1;
                        end
                        for p=o+1:9
                            if isprime(1000000*i+100000*j+10000*k+1000*l+100*m+10*o+p)==1
                                n=n+1;
                            end
                            for q=p+1:9
                                if isprime(10000000*i+1000000*j+100000*k+10000*l+1000*m+100*o+10*p+q)==1
                                    n=n+1;
                                end
                                for r=q+1:9
                                    if isprime(100000000*i+10000000*j+1000000*k+100000*l+10000*m+1000*o+100*p+10*q+r)==1
                                        n=n+1;
                                    end
                                end
                            end    
                        end
                    end
                end
            end
        end
    end
end