The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n.



Task

 Find and print the first 30 cyclotomic polynomials.
 Find and print the order of the first 10 cyclotomic polynomials that have n or -n as a coefficient.


See also
 Wikipedia article, Cyclotomic polynomial, showing ways to calculate them.
 The sequence A013594 with the smallest order of cyclotomic polynomial containing n or -n as a coefficient.
 
&(J=x);                                                    {adjoin x as the variable in the polynomials}
 
Func Cyclotomic(n) =
    if n=1 then x-1 fi;                                    {first cyclotomic polynomial is x^n-1}                           
    r:=x^n-1;                                              {caclulate cyclotomic by division}
    for d = 1 to n-1 do
        if Divides(d,n) then
            r:=r\Cyclotomic(d)
        fi;
    od;
    r.;                                                    {return the polynomial}
 
Func Hascoef(n, k) =
    p:=Cyclotomic(n);
    for d = 0 to Deg(p) do
        if |(Coef(p,d))|=k then Return(1) fi
    od;
    0.;
 
for d = 1 to 30 do
    !!(d,' : ',Cyclotomic(d))
od;
 
for m = 1 to 10 do
    i:=1;
    while not Hascoef(i, m) do
        i:+
    od;
    !!(m,'   :   ',i);
od;