Problems in competitive programming which involve Mathematics are are usually about number theory, or geometry. If you know number theory, that increases your ammo heavily in solving a lot of tougher problems, and helps you in getting a strong hold on a lot of other problems, too.
Problems in competitive programming require insight, so just knowing some topics is not enough at all. All of the problems requires more or less math tough. For instance, solving large systems of equations and approximating solutions to differential equations.
Before we proceed, let us get through the some common set operations.
Q.) What is a Set?
-In mathematics, a set is a collection of distinct objects, considered as an object in its own right.
For example, the numbers 2, 4, and 6 are distinct objects when considered separately, but when they are considered collectively they form a single set of size three, written {2,4,6}.
Sets are one of the most fundamental concepts in mathematics.

A set of polygons in a Venn diagram.
If every member of set A is also a member of set B, then A is said to be a subset of B, written A ⊆ B (also pronounced A is contained in B).
Equivalently, we can write B ⊇ A, read as B is a superset of A, B includes A, or B contains A.
The relationship between sets established by ⊆ is called inclusion or containment.
If A is a subset of, but not equal to, B, then A is called a proper subset of B, written A ⊊ B (A is a proper subset of B) or B ⊋ A (B is a proper superset of A).
Example:
- {1, 3} ⊆ {1, 2, 3, 4}.
- {1, 2, 3, 4} ⊆ {1, 2, 3, 4}.
The empty set (denoted by the symbol ∅) is a subset of every set and every set is a subset of itself:
- ∅ ⊆ A.
- A ⊆ A.

A is subset of B.
There are several fundamental operations for constructing new sets from given sets.



NOTE:
here denotes the number of elements in Set
.
The basic rules of combinatorics one must remember are:
The Rule of Product:
The product rule states that if there are
possibilities from set
and
, then there are
ways to combine one from
and one from
.
The Rule of Sum:
The sum rule states that if there are
possibilities from set
and
possibilities from set
, then there are
ways for either
or
occur assuming the elements of
and
are distinct.


A bijection is a one-to-one mapping between the elements of one set and the elements of another. Counting the size of one of the sets automatically gives you the size of the other set. Exploiting bijections requires us to have a repertoire of sets which we know how to count, so we can map other objects to them.


is also the number of integer solutions to this equation:
Accordingly, some knowledge of the basic combinatorial properties of binary vectors is rather important. Let’s have a look at some simple things associated with them:
since we just choose k positions for our ‘1’s.
.Recurrence relations make it easy to count a variety of recursively defined structures. Recursively defined structures include trees, lists, well-formed formulae, and divide-and-conquer algorithms - so they lurk wherever computer scientists do.
A recurrence relation is an equation which is defined in terms of itself. They are useful because many natural functions are easily expressed as recurrences:



The most important class of counting numbers are the binomial coefficients, where
counts the number of ways to choose
things out of
possibilities.
grid to the lower-right corner by walking only down and to the right? Every path must consist of 
to the right. Every path with a different set of downward moves is distinct, so there are
such sets/paths.
.
count the number of permutations of length
with exactly
ascending sequences or runs. A recurrence can be formulated by considering each permutation
of 1,2,...,n-1. There are n places to insert element n, and each either splits an existing run of p or occurs immediately after the last element of an existing run, thus preserving the run count. Thus
.Working with probabilities is much like conducting an experiment. An outcome is the result of an experiment or other situation involving uncertainty. The set of all possible outcomes of a probability experiment is called a sample space. Each possible result of such a study is represented by one and only one point in the sample space, which is usually denoted by S.
Let's consider the following experiments:
Rolling a die once:
Sample space S = {1, 2, 3, 4, 5, 6}
Tossing two coins:
Sample space S = {(Heads, Heads), (Heads, Tails), (Tails, Heads), (Tails, Tails)}
We define an event as any collection of outcomes of an experiment. Thus, an event is a subset of the sample space S. If we denote an event by E, we could say that E⊆S. If an event consists of a single outcome in the sample space, it is called a simple event. Events which consist of more than one outcome are called compound events.
What we are actually interested in is the probability of a certain event to occur, or P(E). By definition, P(E) is a real number between 0 and 1, where 0 denotes the impossible event and 1 denotes the certain event (or the whole sample space).
.
As stated earlier, each possible outcome is represented by exactly one point in the sample space. This leads us to the following formula:

When two events are said to be independent of each other, what this means is that the probability that one event occurs in no way affects the probability of the other event occurring.
An example of two independent events is as follows; say you rolled a die and flipped a coin. The probability of getting any number face on the die in no way influences the probability of getting a head or a tail on the coin.

If two events A and B are independent, then neither can influence the other, and we can write
.
Conditional probability deals with further defining dependence of events by looking at probability of an event given that some other event first occurs.
Conditional probability is denoted by the following:
.
The above is read as the probability that B occurs given that A has already occurred.
The above is mathematically defined as:
.
When dealing with more than one event, there are certain rules that we must follow when studying probability of these events. These rules depend greatly on whether the events we are looking at are Independent or dependent on each other.
First acknowledge that

.
.









Two events are called mutually exclusive or disjoint if they do not have any outcome common between them. If the two events A and B are mutually exclusive, then A∩B=ϕ (null set).
For three mutually exclusive events A, B and C, we have A∩B∩C=ϕ.




We have defined conditional probability with the following equation:

We can redefine the above using the multiplication rule:

hence
.
In probability theory and statistics, Bayes' theorem describes the probability of an event, based on conditions that might be related to the event.
Bayes' theorem is stated mathematically as the following equation:

where A and B are events
- P(A) and P(B) are the probabilities of A and B without regard to each other.
- P(A | B), a conditional probability, is the probability of A given that B is true.
- P(B | A), is the probability of B given that A is true.
Extended Form
Often, for some partition{Aj} of the event space, the event space is given or conceptualized in terms of P(Aj) and P(B | Aj). It is then useful to compute P(B) using the law of total probability:


We call randomized algorithms those algorithms that use random numbers to make decisions during their execution. Unlike deterministic algorithms that for a fixed input always give the same output and the same running-time, a randomized algorithm behaves differently from execution to execution. Basically, we distinguish two kind of randomized algorithms:
The principle of inclusions-exclusions is as follows:
To calculate the size of combining several sets, it is necessary to sum the sizes of these sets separately, then subtract the size of all pairwise intersections of these sets, add back the sizes of intersections of all possible triples of sets, subtract the sizes of the intersections of fours, and so on, up to the intersection of all sets.
In mathematical form the above verbal formulation is as follows:

It can be written more compactly, using the sum of the subsets. We denote
the set whose elements are
. Then the principle of inclusions-exclusions takes the form:

Let the chart shows three figures
,
and
.

Then the area of their Union
is equal to the sum of the areas
,
and
less double-covered areas
,
and
but with the addition of three covered area
:

Similarly, it can be summarized to Association of n figures.
If there are
(i=1,...,n) events,
their probabilities, the probability of their Association (i.e., what will happen to at least one of these events) is:

This sum can also be written as the sum of the subsets of a set
whose elements are the events
.

For the proof it is convenient to use a mathematical formulation in terms of set theory:

where
, we recall, is the set consisting of
s.
We need to prove that any element contained in at least one of the sets
, will allow for a formula exactly once. (Note that other elements not contained in any of
, can not be considered as absent on the right side of the formula).
Consider an arbitrary element x contained in exactly k>=1 one of the sets of
. We will show that it will be calculated by the formula exactly once.
Note that:
, the item x will be counted exactly k once, with a plus sign;
, the item x will be taken into account (with a minus sign) exactly
once because x it is counted only in those terms that correspond to two sets of k sets containing x;
, the item x will be counted exactly
once, with a plus sign;
, the item x will be counted exactly
once, with the sign
;
, the item x will be counted zero times.
Thus, we need to calculate a sum of binomial coefficients:
.
represents not that other, as
. Therefore
, what we wanted to prove.
and
. You want to count the number of integers in the interval
, coprime with
.
; we denote them using
.
divisible by
? They are:
). Therefore it is necessary to use the formula of inclusions-exclusions.
to iterate over a subset of the set of all
's, calculate their product, and to add or subtract in the formula of inclusions-exclusions next term.Author: Tanmay Chaudhari