Impact of Mg doping contents on the n-type and p-type ZnO by first-principles calculations