In a specified range, I want to get the number of numbers, in which sum of its digits and sum of squares of its digits are prime number. For an example from 2 to 12, there are only 2 numbers which has both its sum of digit and sum of square of its digit are prime number. These two numbers are 11 and 12. In 12, sum of its digit 1+2=3 and sum of square of its digit 1+4=5 are prime numbers.
Although the question is related to programming but it seems that there must be some number theory trick which can solve it quickly. I am very keen to know that trick if at all exists. Thank you.

  • 3
    $\begingroup$ For your grammatical edification: "it's" is NOT possessive; "it's" is short for "it is", which is a complete sentence. "Its" is possessive, and should be used in every place you used "it's" here. (I could just edit, but "teach a man to fish...") $\endgroup$ – The Chaz 2.0 Apr 15 '12 at 18:18
  • $\begingroup$ @TheChaz: Thank you for the information. i have corrected it. If anywhere you find any grammatical mistakes, please let me know. :) $\endgroup$ – Ravi Joshi Apr 15 '12 at 18:41
  • $\begingroup$ The other two most common homophone mistakes are you're/your and they're/their/there. $\endgroup$ – The Chaz 2.0 Apr 15 '12 at 20:35
  • 2
    $\begingroup$ Discussed as a programming problem at codereview.stackexchange.com/questions/8319/… $\endgroup$ – Gerry Myerson Apr 16 '12 at 0:25

Analytic number theory could produce a heuristic for approximately how many numbers up to $x$ satisfy your two conditions (that is, a predicted asymptotic formula), but I doubt it can be proved. Even if it could, it would only give the answer approximately, not exactly as you seem to want. So I don't think there's any trick besides a brute-force calculation.

  • $\begingroup$ Okay... thanks a ton. $\endgroup$ – Ravi Joshi Apr 15 '12 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.