All right, thanks to everybody's help, I've got the algorithm for determining the nth roots of unity.
However, for determining which ones are primitive, I'm still having a little trouble.
If n is odd, I can test if (n, k) are coprime. However, for even values of n, it seems that it doesn't...