How to solve this problem?[solved]

https://hack.codingblocks.com/contests/c/528/821

Basically this is an application of inclusion/exclusion principle .
Its answer is nothing but
(suppose T(n) denotes number of nos divisible by n)
sum(T(j))(j is prime less than 20) - sum(T(2*3)+T(2,5)+T(2,7)+… sum taking two at a time)+(sum taking three at a time) -… so on
You can do this using recursion in which every call you add a current prime or don’t . And base call will be
add answer to the final ans variable if number of elements is odd Otherwise subtract
For more clarification , go through this code
https://ide.codingblocks.com/s/41143

1 Like