Let z
be a complex number. z
is an nth primitive root of unity if for a certain positive integer n
and for any positive integer
k < n
.
Challenge
Write a full program or function that, given a positive integer n
as input, outputs all of the nth primitive roots of unity. You may output them in polar form (e^θi
or e^iθ
, argument should be a decimal with at least 2 decimal places) or rectangular form (a + bi
or a similar form, real and imaginary parts should also be decimals), and they may be outputted in your language's list/array format or as a string with the numbers separated by spaces or newlines. Built-ins that calculate the nth roots of unity or the nth primitive roots of unity are not allowed.
This is code-golf, so shortest code in bytes wins.
Sample Inputs and Outputs
6 -> e^1.05i, e^-1.05i # polar form
3 -> e^2.094395i, e^-2.094395i # any number of decimal places is OK as long as there are more than 2
8 -> 0.707 + 0.707i, 0.707 - 0.707i, -0.707 + 0.707i, -0.707 - 0.707i # rectangular form
1 -> 1 + 0i # this is OK
1 -> 1 # this is also OK
4 -> 0 + i, 0 - i # this is OK
4 -> i, -i # this is also OK