Let $P$ be a two-digit prime number less than $100$ such that both digits are prime numbers. What is the sum of all such numbers, $P$?

Is there a quick way to solve this problem without listing all the numbers?

  • $\begingroup$ Yes. Just list those numbers both of whose digits are prime. $\endgroup$ – WillO Jan 27 '15 at 1:04
  • $\begingroup$ It is not such a big list as you perhaps imagine. Note that the unit digit is quite restricted. Your Question should be fully stated within the body, not relying on the title alone for its formulation. $\endgroup$ – hardmath Jan 27 '15 at 1:25

Probably not -- the only valid digits are 2, 3, 5 and 7, so there are only 16 possibilities to check, which is surely faster than to try to be clever.

In fact, 2 and 5 clearly can't be the last digit, so there are only 8 actual values to try.

  • $\begingroup$ You can eliminate two more pairs because the digits cannot be equal. $\endgroup$ – N. S. Jan 27 '15 at 1:24
  • $\begingroup$ @N.S.: Yes, but then we're arguably reaching the point where it is quicker just to eliminate each of them individually than to formulate a general rule to cover them. $\endgroup$ – Henning Makholm Jan 27 '15 at 1:55

Simple in Mathematica:

Total@Select[Flatten@Outer[10 #1 + #2 &, mylist = Prime[#] & /@ Range[4], mylist], PrimeQ]

(* 186 *)

  • $\begingroup$ And why would this solution be voted down, when "answers" that merely state which digits need be considered are voted up, such as @HenningMakholm's? $\endgroup$ – David G. Stork Jan 27 '15 at 16:57
  • $\begingroup$ I didn't DV, but my guess is: Because the question isn't "what are they" but rather "is there a better way to find them?" ... and, to the extent that i can understand what you did to find them (which you didn't explain), it is the same mechanism the OP wanted to improve upon. So you aren't answering the question asked, but the question that raised this question. $\endgroup$ – Vynce Jul 20 '15 at 6:59
  • $\begingroup$ The "better way" is clearly to write a single, simple line of code. $\endgroup$ – David G. Stork Jul 20 '15 at 15:46
  • $\begingroup$ ...which one doesn't understand? not a great way to go about getting math right, i think. Had you said "No, because that way is this easy" and also clarified what your code did, i suspect there would have been no downvote. But the combination of not actually answering the question asked, and not answering comprehensibly, make it pretty far from a "good" answer. PS arguing with reasons given for why a downvote is a good way to stop getting reasons given. $\endgroup$ – Vynce Jul 20 '15 at 22:24

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.