Let Fq be a finite field of odd order q and , where a,a1,a2 are positive integers, p1,p2 are distinct odd primes and 4p1p2|q−1. In this paper, we study the irreducible factorization of xn−1 over Fq and all primitive idempotents in the ring Fq[x]∕〈xn−1〉.Moreover, we obtain the dimensions and the minimum Hamming distances of all irreducible cyclic codes of length n over Fq.