AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() The standard interpretation leads to the principle of inclusion-exclusion. Time complexity is, with equals to the number of distinct prime factors of. However, using the restricted inclusion-exclusion principle, we can convert the problem into computing the size of the intersection of sets, which is trivial. Let be the set of numbers that are divisible by, then the answer is the, which may be hard to compute directly. To do this, we can first sieve all primes not exceeding and then find all prime factors of. How we're gonna compute ? Instead of counting the numbers that are coprime with, we can count the numbers that aren't coprime with, that is, sharing at least one prime factor with. If we can compute the number of integers in the interval such that is coprime with, denoted as, then the answer is. Let's see an example problem Co-prime where this principle could be applied: Given, you need to compute the number of integers in the interval such that is coprime with, that is. The count on the left-hand side is, and on the right hand side, we haveĮxample 1. Suppose, and more precisely, that is in exactly of the sets. If, then it's counted once on either side. It's not hard to prove the correctness of this formula, we can just check how often an element is counted in both sides. This is a formula which looks familiar to many people, I'll call it The Restricted Inclusion-Exclusion Principle, it can convert the problem of calculating the size of the union of some sets into calculating the size of the intersection of some sets. The Restricted Inclusion-Exclusion Principle. ![]() The following formula addresses the case applied to more sets. Now the count is correct except for the elements in which have been added three times, but also subtracted three times. Unless are pairwise disjoint, we have an overcount, since the elements of has been counted twice. I'll start with the basic formula, one can choose to skip some of the text depending on your grasp with the topic.Ĭonsider a finite set and three subsets, To obtain, we take the sum + +. Most of the describing text are from the graduate text book Graduate Text in Mathematics 238, A Course in Enumeration, and the problems are those that I encountered in real problem set, so if possible, I'll add a link to the real problem so that you can solve it by yourself. So, what I am going to pose here, is somewhat the "Generalized Inclusion-Exclusion Principle". ![]() Also, after some few investigations, the so-called "Inclusion-Exclusion principle" some people claim that they know wasn't the generalized one, and has little use when solving problems. I found that although many claim that they do know this topic well, problems concerning inclusion-exclusion principle are sometimes quite tricky and not that easy to deal with. Hello, Codeforces! The reason why I am writing this blog is that my ACM/ICPC teammate calabash_boy is learning this technique recently(he is a master in string algorithms,btw), and he wanted me to provide some useful resources on this topic.
0 Comments
Read More
Leave a Reply. |