Need some clarification in question - Problem - Not So Easy Math [Inclusion-Exclusion]

when n = 10
ans = 9

number divided by 2
2 , 4 , 6 , 8 , 10 = 5
number divider by 3
3,6,9 = 3
number divided by 5
5,10 = 2
number divided by 7
7 =1

if we are considering numbers that are repeated(6,10) than ans = 11
otherwise 9

when n = 12
ans = 14

if we are considering repeating number than answer is 14 otherwise answer is 11.

Please correct my understanding .

The question is to find the number of numbers that are divisible by prime numbers upto 20. So if x is divisible by any of the prime number under 20, it qualifies to increase the count of the answer by 1. It doesn’t matter if x can be divided by more than one number, you only need to check if x is to be considered in the final answer or not, that’s it.

in that case for n = 10 answer should be 11 but its 9
number divided by 2
2 , 4 , 6 , 8 , 10 = 5
number divider by 3
3,6,9 = 3
number divided by 5
5,10 = 2
number divided by 7
7 =1

The valid numbers are : 2, 3, 4, 5, 6, 7, 8, 9, 10.
These are the numbers that are divisible by any of the primes under 20.

i think you mean any prime under 20 that are less than or equal to 10 (when n = 10)

but should we increase the answer count when any number is divisible by more than one prime number or it should be counted once only .

Count each valid number once.
You can check for all primes under 20. Numbers will not be divisible for that case.

in that case for n = 12 answer should be 11 but its 14

2,3,4,5,6,7,8,9,10,11,12

It is 11, check the order again.

my bad :frowning: . Thanks @LP-OL0008

1 Like