Interview Q&A / Aptitude

BeginnerQuick answer1 min readUpdated 3 Oct 2026

A number is picked at random from 1 to 50. What is the probability that it is divisible by 3 or 5?

SHORT ANSWER

23/50. Multiples of 3: 16. Multiples of 5: 10. Multiples of both (15, 30, 45): 3. By inclusion-exclusion, 16 + 10 - 3 = 23 favourable numbers out of 50.

Explain it simply

When you count "A or B", the items that are in both get counted twice if you just add. Numbers like 15 and 30 are multiples of both 3 and 5, so subtract them once. This rule, P(A or B) = P(A) + P(B) - P(A and B), is called inclusion-exclusion.

Example

Question: Random number from 1 to 50. P(divisible by 3 or 5)?

  1. Multiples of 3: floor(50/3) = 16.
  2. Multiples of 5: floor(50/5) = 10.
  3. Multiples of 15: floor(50/15) = 3.
  4. Favourable = 16 + 10 - 3 = 23.
  5. P = 23/50.

Related: P(divisible by neither) = 1 - 23/50 = 27/50.

js
let n = 0;
for (let i = 1; i <= 50; i++) if (i % 3 === 0 || i % 5 === 0) n++;
console.log(n); // Output: 23

What to say in the interview

"I count multiples of 3 and of 5, then subtract the multiples of 15 which got counted twice. 16 plus 10 minus 3 is 23, so 23 over 50."

Common mistakes

  • Adding 16 + 10 = 26 and forgetting the overlap.
  • Counting multiples of 15 as 50/15 = 3.33 instead of the whole number 3.

#aptitude#probability#inclusion-exclusion

Related questions

Practise more Aptitude questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Aptitude quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.