On the relationship between Yang-Mills theory and gravity and its implication for ultraviolet divergences