How is the degree of unsaturation derived? The formula for degrees of unsaturation is: 

$$1+ \frac{1}{2} \sum ( n_i (v_i-2))$$

$v_i$ = valency of atom
$n_i$ = number of atoms with that valency

Could someone explain how the formula works, and why divalent atoms don't contribute to unsaturation (as evident from the formula).
This is the correct formula:

$$ DU = 1 + \frac{1}{2}\sum _{v=1}^{j} n_{i}(v-2),$$
where

$j$ = maximum valence of any atom in molecule
$v$ = valence of atom(s) 1 to whatever
$n_{v}$ = number of atoms with that valence

Wikipedia gives a good explanation. In simple terms the formula will give the number of double bonds in an alkene. For all alkanes the number would be 0 of course. Rings and ethynes would complicate the use of the formula. Think of using the equation on chemical formulas like $\ce{C_{x}}\ce{H_{y}}$ or $\ce{C_{x}}\ce{H_{y}}\ce{O_{z}}$.