Inclusion-Exclusion principle. Add all the numbers that are divisible by - a and d - a and e - a and f - b and d - ... - c and f
Subtract all the numbers that are divisible by - a, b and d - a, c and d - b, c and d - ... - c, e and f Add back all the numbers that are divisible by - a, b, c and d - ... - c, d, e and f. ... igor On 2 April 2012 11:36, vivek dhiman <[email protected]> wrote: > Hi all smart people. > > if there are two set of numbers (both sets are of size 3) > (a,b,c) and (d,e,f) > > given a number k, how will you count all numbers(n) < k that are divisible > by both x and y > where x is any number from set (a,b,c) > and y is any number from set (d,e,f) > > remember you should take care of repetitions.. > > Thing is I am doing this using sets and iterators which is taking much > more time ..suggest some better approach .. > No need to write code... just the approach.. > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-code?hl=en. > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
