I was asked this question about finding a number and three clues were given which are as follows.

  1. If this number is multiple of 5, it would lie between 1 to 19.
  2. If this number is not multiple of 8, it would lie between 20 to 29.
  3. If this number is not multiple of 10, it would lie between 30 to 39.

I have tried a lot, but couldn't find any solution. Hope someone can help me. Thanks.

  • 2
    $\begingroup$ Similar question with different numbers. $\endgroup$
    – f''
    Feb 29, 2016 at 13:18
  • 1
    $\begingroup$ You could just make a truth table in a spreadsheet. You only need to consider $39$ choices. Numbers in a column, conditions in a row, copy down. $\endgroup$ Mar 1, 2016 at 3:24

7 Answers 7


The correct answer is:


This answer meets the conditions, because:

It is not a multiple of $5$ and not in $[1, 19]$, it is a multiple of $8$, so it is not in $[20, 29]$, and it is not a multiple of $10$, so it is in $[30, 39]$

So how can we get the number?

Any multiple of $5$, must be in $[1, 19]$. However, all multiples of $5$ in that range are not multiples of $8$, so they must be in $[20, 29]$, so obviously that is not the answer.

But what about?

A non-multiple of $8$ in that range will also be a non-multiple of $10$, except for $20$, but $20$ is a multiple of $5$, so we have no valid answers here.


Finally, we are looking for a non-multiple of $5$, which is also a multiple of $8$ and a non-multiple of $10$, and is in the range $[30, 39]$. The only one such in that range is $32$.

Thus there is no other number that satisfies all condition.


The answer is :


If we have to choose a number from natural numbers, then :

  • Any number we choose say $x \gt 39$; if $x$ is a multiple of $10$, then $x$ also a multiple of $5$. So as per rule no. $1$, $x$ should be in the range $[1,19]$. So $x$ cannot be greater than $39$.
  • But then, the only multiple of $10$ (and $5$) in the range as per rule $1$, $x$ should be 10. Then as per rule $2$, since $10$ is not a multiple of $8$, $x$ has to be in the range $[20,29]$. Thus, it causes a contradiction!
  • And if we choose a number (this time $y$) which is not a multiple of $10$, then it has to be in the range $[30,39]$. (holding onto this branch for further possibilities...)
  • Also, a point to note that if we do the same for rule $2$, i.e. choose a number $x$, which is not a multiple of $8$, then we need to make sure that $x$ is a multiple of $10$ (by rule $3$). But by rule $1$, it's another contradiction!!


We need a number $y$, which is in range $[30,39]$, a multiple of 8 and not a multiple of 5 or 10. So, $\{30,31,32,33,34,35,36,37,38,39\}$ we cancel : 30 , 35 , and the only acceptable number(multiple of $8$) left is $32$.


Do you enjoy programming? Try this in Java:

public void findTheDangNumber() {
    for (int i = 1; true; i++){
        if (i % 5  == 0 && (i <= 1  || i >= 19)) continue;
        if (i % 8  != 0 && (i <= 20 || i >= 29)) continue;
        if (i % 10 != 0 && (i <= 30 || i >= 39)) continue;
        System.out.println("answer: " + i);

What's happening is we are running until all of the conditions are met. Each "if" line basically says, "if it's divisible by the given number and is outside of the range, then skip to the next number." If each of the "if" lines is satisfied, then we've found our answer and we print it out!

Note: Thanks to @Ethan for help with the logic.

  • 1
    $\begingroup$ Oh that's something I can understand, what a neat answer sir! +1 $\endgroup$
    – Kyle
    Feb 29, 2016 at 20:15
  • $\begingroup$ You actually can't assume that the number is somewhere in the "lie between" condition. Suppose the last clause were "i % 16 != 0" instead. Then 48 would the lowest valid answer. You can go through the effort of proving that the answer lies between 1 and 39, but that proof is effectively a solution to the riddle. $\endgroup$
    – Ethan
    Feb 29, 2016 at 20:31
  • $\begingroup$ @Ethan if the last condition were "If this number is not multiple of 16, it would lie between 30 to 39", then 16 would be the lowest valid answer. I hear your basic point, though. $\endgroup$
    – Brian Risk
    Feb 29, 2016 at 21:35
  • $\begingroup$ Your code appears to find the lowest valid number and then stop. It doesn't prove that there aren't others. It's true that there aren't but how does your code account for that? $\endgroup$
    – Octopus
    Mar 1, 2016 at 0:01
  • 1
    $\begingroup$ @BrianRisk what a nice approach. very gud. $\endgroup$
    – A J
    Mar 1, 2016 at 5:40

Let's find all solutions using formal logic.

Given a logic statement of the form "if $A$ then $B$", we can express it symbolically as $A \implies B$ or its equivalent, $\bar A \lor B$.

Numbering the given statements 1,2,3 respectively, we have
$A_1$ = the truth value of this number is a multiple of 5,
$B_1$ = the truth value of this number would lie between 1 to 19,
and so on.

Let $E$ be (the truth value of) the conjunction of the 3 statements. Then: $$\begin{align} E = & (\bar A_1 \lor B_1) (\bar A_2 \lor B_2) (\bar A_3 \lor B_3) \\ = & \bar A_1 \bar A_2 \bar A_3 \lor \bar A_1 \bar A_2 B_3 \lor \bar A_1 B_2 \bar A_3 \lor \bar A_1 B_2 B_3 \\ & \lor B_1 \bar A_2 \bar A_3 \lor B_1 \bar A_2 B_3 \lor B_1 B_2 \bar A_3 \lor B_1 B_2 B_3 \end{align}$$

Now, since every multiple of 5 is also a multiple of 10, the conjunction $A_1 A_3$ must be false because it asserts that the number is a multiple of 5 and not a multiple of 10.

Also, $B_i B_j$ is false if $i \neq j$ because the intervals being disjoint means that the number cannot be simultaneously a member of two intervals.

We can therefore simplify to get $E = \bar A_1 \bar A_2 B_3 \lor B_1 \bar A_2 \bar A_3$.

The first term requires a multiple of 8 from the interval 30 to 39 that is not a multiple of 5, so 32 is a solution.

The second term requires a multiple of 8 and 10 from the interval 1 to 19. There aren't any.

Hence 32 is the only solution.


The answer is:


Here are my deductions:

1. The number is not a multiple of $8$ and $10$. If it were, then it must necessarily be a multiple of $5$ and be in the range $[1, 19]$. None of the numbers in that range fit the criteria.

2. The number is a multiple of either $8$ or $10$. If it weren't, then it would have to be in both $[20, 29]$ and $[30, 39]$ — a contradiction.

3. From the second deduction we can narrow things down to the following numbers: $20, 32$.

4. The answer must be $32$ since $20$ doesn't meet the first condition.

In hindsight, the first deduction is unneeded. I've kept it since that's how I initially processed the last two conditions.


Let's call the answer $N$.

First suppose $N$ is a multiple of $5$. Then $N$ must be in the range $1-19$, so $N$ is either $5, 10$, or $15$. None of these is a multiple of $8$, and therefore $N$ must be in the range $20-29$. That's a contradiction, so we know $N$ isn't a multiple of $5$.


we also know $N$ isn't a multiple of $10$, so $N$ is definitely in the range $30-39$. That means $N$ is not in the range $20-29$, so $N$ must be a multiple of $8$.


$N$ is a multiple of $8$ in the range $30-39$, so $N=32$.


It's impossible for it to be divisible by 5 without being divisible by 8 or 10, so it can only be outside of the range if it's really a multiple of 5. Otherwise it can't be a multiple of 10, so it falls into the 3rd category, and this category only, thus it has to be div. by 8. The only suitable number would be 32.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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