# Gauss-like product $\prod_{k=1}^{(p-1)/2}\csc\frac{\pi k^2}p$

Let $$p$$ be an odd prime. Denote $$S_p=\frac{\sqrt p}{2^{(p-1)/2}}\prod_{k=1}^{(p-1)/2}\csc\frac{\pi k^2}p.$$ I conjecture that:
(i) For $$p\equiv1\pmod4$$, $$S_p$$ is the fundamental unit of field $$\mathbb Q[\sqrt p]$$.
(ii) For $$p\equiv3\pmod4$$, $$S_p=\pm1$$.
Can we prove or disprove them? Moreover, (iii) can we calculate the sign of $$S_p$$ when $$p\equiv3\pmod4$$?

I have made some progress proving (ii).
When $$p\equiv3\pmod4$$, $$S_p^2=\frac{p}{2^{p-1}}\left(\prod_{k=1}^{(p-1)/2}\csc\frac{\pi k^2}p\right)^2$$ Using some basic facts in number theory, we know $$\pm k^2\bmod p$$ runs over $$1$$ to $$p-1$$ when $$k=1,\ldots,(p-1)/2$$. Therefore we have $$S_p^2=\frac{p}{2^{p-1}}\prod_{k=1}^{p-1}\csc\frac{\pi k}p=1.$$ But I have no idea how to solve (i) and (iii).

Your conjecture on $$p\equiv 1 \pmod{4}$$ is correct except missing the class number, making the smallest counterexample at $$p=229$$. It follows from the class number formula.
Consider the case $$p\equiv 1 \pmod{4}$$, $$K=\mathbb{Q}(\sqrt{p})$$, $$\varepsilon > 1$$ be the fundamental unit, $$K$$ is associated with the quadratc character $$\chi = (\cdot | p)$$. Factorization of Dedekind zeta function $$\zeta_K(s) = \zeta(s) L(s,\chi)$$ implies
$$\frac{h \log \varepsilon}{\sqrt{p}} = L(1,\chi) = -\frac{2G(\chi)}{p} \sum_{k=1}^{(p-1)/2} \chi(k)\log(\sin \frac{k \pi}{p})$$ where $$h$$ is class number of $$K$$, $$G(\chi)$$ is the Gauss sum $$\sum \chi(k) e^{2\pi i k /p}$$. It is a non-trivial result that $$G(\chi) = \sqrt{p}$$ (when $$p\equiv 1 \pmod{4}$$). Some rearrangement gives $$\varepsilon^h = \frac{\sqrt p}{2^{(p-1)/2}}\prod_{k=1}^{(p-1)/2}\csc\frac{\pi k^2}p$$