title: lucky number or not
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9018614/algorithm-to-find-lucky-numbers">Algorithm to find Lucky Numbers</a>  </p>
  </blockquote>
  
  
  
  <p>I came across this question.A number is called lucky if the sum of its   digits, as well as the sum of the squares of its digits is a prime number.        How many numbers between A and B are lucky? 1 &lt;= A &lt;= B &lt;= 10^18.  </p>
  
  <p>I tried this,
      First I generated all possible primes between 1 and the number that could be resulted by summing the squares (81 *18 = 1458).[Note: I used sieve of Atkin's approach for prime number generation].<br>
      And then verifying each number's digit sum and digit square sum is in the list of primes, if so it is lucky otherwise not. But this is very very slow. Is there any better way of solving?</p>