A inclusion -exclusion related problem Cicada is an insect with large transparent eyes and well-veined wings similar to the "jar flies". 
The insects are thought to have evolved 1.8 million years ago during the Pleistocene epoch. 
There are about 2,500 species of cicada around the world which live in temperate tropical climates.
These are all sucking insects, which pierce plants with their pointy mouthparts and suck out the juices. 
But there are some predators (like birds, the Cicada Killer Wasp) that attack cicadas. 
Each of the predators has a periodic cycle of attacking Cicadas. 
For example, birds attack them every three years; wasps attack them every 2 years. 
So, if Cicadas come in the 12th year, then birds or wasps can attack them.
If they come out in the 7th year then no one will attack them.
So, at first they will choose a number N which represents possible life-time. 
Then there will be an integer M indicating the total number of predators.
The next M integers represent the life-cycle of each predator.
The numbers in the range from 1 to N which are not divisible by any of those M life-cycles numbers will be considered for cicada's safe-emerge year.
Given N ,M and the life cycles of the predators,I have to find out the number of safe-emerge days for cicada.
For example,N=15,M=3 and the life cycles of the predators are 2,3 5 the result will be 4.
Someone found out it using inclusion-exclusion principle.He didn't show me the process.
Can anyone tell me how this problem can be solved using inclusion-exclusion with great details and better explanation.
 A: With inclusion-exclusion we work in terms of sets: sets of years in this case. So define sets:
\begin{eqnarray*}
L &=& \left\{\mbox{years of cicada's life}\right\} = \left\{1,2,\ldots,N\right\} \\
P_i &=& \left\{\mbox{years of the $i^{th}$ predator}\right\}, \quad i = 1,2,\ldots,M \\
S &=& \left\{\mbox{safe years for cicada. i.e. years with no predator} \right\}.
\end{eqnarray*}
We want $\vert S \vert$ and we find it as follows:
\begin{eqnarray*}
\left| S \right| &=& \left| L \right| - \left|\; \bigcup_{i=1}^M{P_i} \;\right| \\
&=& N - \left[ \sum_{i=1}^M{ \left| P_i \right|} - \sum_{i \lt j}{ \left| P_i \cap P_j \right|} + \sum_{i \lt j \lt k}{ \left| P_i \cap P_j \cap P_k \right|} - \cdots - (-1)^M \left| P_1 \cap \cdots \cap P_M \right| \right] \\
&& \qquad\qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \mbox{by Inclusion-Exclusion Principle.}
\end{eqnarray*}
We can show how this works using your example, where: $N = 15, M = 3$ and
\begin{eqnarray*}
P_1 &=& \{2,4,6,8,10,12,14\} \\
P_2 &=& \{3,6,9,12,15\} \\
P_3 &=& \{5,10,15\}.
\end{eqnarray*}
We firstly find the intersections we need:
\begin{eqnarray*}
P_1 \cap P_2 &=& \{6,12\} \\
P_1 \cap P_3 &=& \{10\} \\
P_2 \cap P_3 &=& \{15\} \\
P_1 \cap P_2 \cap P_3 &=& \emptyset. \\
\end{eqnarray*}
Then our equation gives us: $$\left| S\right| = 15 - \left[ (7+5+3) - (2+1+1) - 0 \right] = 4$$
which is the answer you have.
