UVa 10533 - Digit Primes

Summary
A prime number that its sum of digits is also a prime number is consider as "digit prime". Count the number of "digit prime" numbers in a given range.

Explanation
Use Sieve of Eratosthenes and a simple DP.

Gotchas

 * Since there are quite a number of test inputs, (0<N<=500000), counting on demand will easily result in TLE.

Input
5 10 20 10 100 100 10000 1 999999 1 999998

Output
1 10 576 30123 30123