Minimal cyclotomic field containing a given quadratic field? There was an exercise labeled difficile (English: difficult) in the material without solution:

Suppose $d\in\mathbb Z\backslash\{0,1\}$ without square factors, and $n$ is the smallest natural number $n$ such that $\sqrt d\in\mathbb Q(\zeta_n)$, where $\zeta_n=\exp(2i\pi/n)$. Show that $n=\lvert d\rvert$ if $d\equiv1\pmod4$ and $n=4\lvert d\rvert$ if $d\not\equiv1\pmod4$.

It's easier to show that $\sqrt d\in\mathbb Q(\zeta_n)$, although I haven't worked out every epsilon and delta: First we can factor $d$ as a product of unit and prime numbers. Note that a quadratic Gauss sum $g(1,p)=\sum_{m=0}^{p-1}\zeta_p^{m^2}=\sqrt{(-1)^{(p-1)/2}p}\in\mathbb Q(\zeta_p)$, and that $\sqrt2\in\mathbb Q(\zeta_8)$. From this we can deduce that $\sqrt d\in\mathbb Q(\zeta_n)$, where $n=\lvert d\rvert$ if $d\equiv1\pmod4$ or $4\lvert d\rvert$ otherwise.
I have no idea how to show that $n$ is minimal. I hope we'll have some proof without algebraic number theory, which is all Greek to me.
Any help is welcome. Thanks!
 A: As you've surmised, one can simply count all index-$ 2 $ subgroups of the Galois group, which we know how to compute using the Chinese remainder theorem. We have the following general result: let $ n = 2^{r_0} \prod_{i=1}^n p_i^{r_i} $ be the prime factorization of $ n $. We have the following for $ r_0 = 0, 1 $:
$$ \textrm{Gal}(\mathbf Q(\zeta_n) / \mathbf Q) \cong \prod_{i=1}^n C_{p_i^{r_i - 1}(p_i - 1)} $$
and the following for $ r_0 \geq 2 $:
$$ \textrm{Gal}(\mathbf Q(\zeta_n) / \mathbf Q) \cong C_2 \times C_{2^{r_0 - 2}} \times \prod_{i=1}^n C_{p_i^{r_i - 1}(p_i - 1)} $$
In the former case, we have $ 2^n - 1 $ surjective homomorphisms to $ C_2 $, which correspond to the obvious quadratic subfields generated by square roots of the square-free products of the (signed according to Gaussian period theory) odd primes dividing $ n $. In the latter case, we have $ 2^{n+2} - 1 $ surjective homomorphisms to $ C_2 $ if $ r_0 > 2 $, and $ 2^{n+1} - 1 $ if $ r_0 = 2 $, which correspond to to the following quadratic subfields $ \mathbf Q(\sqrt{d}) $:


*

*$ d = \pm \prod p_i $ for all odd primes dividing $ n $: $ 2^{n+1} - 1 $ quadratic subfields in total.

*(For $ r_0 > 2 $) $ d = \pm 2 \prod p_i $ for all odd primes $ p_i $ dividing $ n $, $ 2^{n+1} $ quadratic subfields in total.


where the primes $ p_i $ are again all signed according to Gaussian periods. (All of this can be summarized as "the only quadratic subfields are the obvious ones".) From all of this, we have completely classified the quadratic subfields of a cyclotomic field, and we are ready to attack the problem. Let $ \mathbf Q(\zeta_n) $ be a cyclotomic field containing $ \sqrt{d} $, where $ d $ is square-free. $ n $ must certainly be divisible by every prime factor of $ d $ by our above analysis, and thus must be divisible by $ d $. This means that $ \mathbf Q(\zeta_d) \subset \mathbf Q(\zeta_n) $. If $ d $ is $ 1 $ modulo $ 4 $, then primes that are $ 3 $ modulo $ 4 $ come in pairs, therefore the negative signs in the square roots vanish when we take a product, and thus $ \sqrt{d} \in \mathbf Q(\zeta_d) $, which shows that this is the minimal cyclotomic field containing $ \sqrt{d} $ in this case.
If $ d $ is $ 2 $ modulo $ 4 $, then our above analysis shows that the multiplicity of $ 2 $ in $ n $ must be at least $ 3 $, therefore $\mathbf Q(\zeta_{4d}) \subset \mathbf Q(\zeta_n) $ (note that $ \textrm{lcm}(8, d) = 4d $!) On the other hand, it is easily seen that $ \mathbf Q(\zeta_{4d}) $ contains $ \sqrt{d} $, so it is the minimal such cyclotomic field.
Finally, if $ d $ is $ 3 $ modulo $ 4 $, then $ \sqrt{-d} \in \mathbf Q(\zeta_d) \subset \mathbf Q(\zeta_n) $, and hence $ \sqrt{-1} = \zeta_4 \in \mathbf Q(\zeta_n) $. From our above classification, we know that this implies $ r_0 \geq 2 $, so that $ n $ is divisible by $ 4 $. Once again we see that $ \mathbf Q(\zeta_{4d}) \subset \mathbf Q(\zeta_n) $, and clearly $ \sqrt{d} = \zeta_4 \sqrt{-d} \in \mathbf Q(\zeta_{4d}) $, concluding the proof.
This proof can be significantly shortened if one uses ramification theory for the above analysis instead of a direct computation using the Galois groups. Nevertheless, the above proof is purely Galois theoretic.
A: I don't think that your answer to @JyrkiLahtonen could give the solution because, once again, how do you  deal with the minimality problem ? Jyrki's hint at the discriminant is the right one... provided you appeal to CFT, here the Kronecker-Weber theorem since the base field is $\mathbf Q$: every abelian extension $K/\mathbf Q$ is contained in a cyclotomic field $\mathbf Q (\zeta_n)$, and the minimal such $n$ is called the conductor of $K$. For a quadratic field $K = \mathbf Q (\sqrt d)$, the conductor of $K$ is the absolute value of the discriminant, which is $d$ if $d \equiv 1 mod 4$, or $4d$ otherwise. This is a theorem. It is weird that this difficile exercise is given without at least a reference to ANT (ramification).
