I noticed a strange phenomenon while examining prime numbers. Here it is:

We'll say num = number
If num's sum of digits is 4 and num is not even, num is prime.
Can somebody explain to me why this happens?

Here is a Node.js program for proof: http://pastebin.com/a35uXxKk

EDIT: Output:

13 (Is prime as well) 31 (Is prime as well) 103 (Is prime as well) 211 (Is prime as well) 301 (If you see this, something is wrong) 1003 (If you see this, something is wrong) 1021 (Is prime as well) 1201 (Is prime as well) 2011 (Is prime as well) 3001 (Is prime as well)

This means numbers with (If you see this, something is wrong) are exceptions. Can people help me make a rule for ruling out these exceptions?


Most of the exceptions are divisible by 11. Taking out those seemed to eliminate most exceptions.


It seems if a number got ruled out by my previous revisions, any of the digit rearrangements will not work either.

Comment why if you downvote so I can improve


closed as unclear what you're asking by Rob Arthan, user147263, Leucippus, John B, Semiclassical May 8 '16 at 0:09

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ $1111 = 11\cdot 101$ $\endgroup$ – Ant May 7 '16 at 22:34
  • $\begingroup$ I don't know, my program says that is prime as well $\endgroup$ – TigerGold May 7 '16 at 22:34
  • 4
    $\begingroup$ Can I mention $110011=11\cdot10001$? $\endgroup$ – bof May 7 '16 at 22:37
  • 4
    $\begingroup$ Another exception is $121 = 11^2$. $\endgroup$ – Zoe H May 7 '16 at 22:38
  • 3
    $\begingroup$ $11000000000000010001$ is an example of a odd number with digit sum 4, not divisible by $11$ and not prime. $\endgroup$ – Henrik May 7 '16 at 23:26

You've asked for an explanation for what you saw, and even though it isn't correct, some things can be said about why counterexamples aren't smaller than they are.

By requiring the numbers to be odd, you exclude multiples of $2$.

As the iterated digital sum of a number equals the number's residue modulo $9$, a neccessary (but far from sufficient) condition for that requirement to be fulfilled, is that the number is of the form $9k+4$, that shows us that you've ruled out all multiples of $3$.

As the odd multiples of $5$ end with a $5$, they can't have $4$ as the sum of their digits, which means you've ruled out multiples of $5$.

So you've ruled out a lot of non-primes.

In general only a few numbers between $49$ (the square of the lowest prime you haven't ruled out and $999$ have $4$ as the sum of their digits and by coincidence (?, arguments can possibly be found, and I haven't actually checked) none of them are prime. Which explains why you didn't see any counterexamples, and they start appearing not long after $1000$ (it has been mentioned may times in the comments that $1111=11\cdot 101$ is a counter example).

Then you can rule out multiples of $11$ (your edit) and have a rule that holds a little longer, but counterexamples will still exist (I've given one in the comments, where $17$ is the smallest prime factor - I generated that by "randomly" inserting $0$'s to $1111$, so it's unlikely to be the smallest).


This is not true. Your program is, unfortunately, written incorrectly:

number % i === 0 && !i === number && !i == 1

!i === number is not correct logic because you're taking the negation of i, which makes no sense in this scenario. You need to use the !== operator when checking if two values are unequal, so it should be this:

number % i === 0 && i !== number && i !== 1

Another valid solution is to put the == expression in parentheses so you take the negation of the whole Boolean expression:

number % i === 0 && !(i === number) && !(i === 1)
  • 1
    $\begingroup$ Oh, just fixed it $\endgroup$ – TigerGold May 7 '16 at 22:41

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