The residue theorem and its applications