An extension of a result of Lehmer on numbers coprime to n