orthogonality relation for quadratic Dirichlet characters Hello, 
I've been working deriving the orthogonality relation for quadratic Dirichlet characters $\chi_d(n)$ (or real primitive characters). The statement I'm trying to prove is 
$$\lim_{X \rightarrow \infty} \frac{1}{D} \sum_{0 < |d| \leq X} \chi_d(n)= \begin{cases}
 \prod_{p|n} \left(1 + \frac{1}{p}\right)^{-1} \quad &\text{if $m$ is a perfect square,} \newline
 0 \quad &\text{otherwise,}
\end{cases}$$ 
where the sum ranges over fundamental discriminants $d$ and $D$ is the number of terms appearing in the sum. 
You could recast this as 
$$\lim_{X \rightarrow \infty} \frac{1}{D} \sum_{0 < |d| \leq X} \chi_d(n)\chi_d(m)= \begin{cases}
 \prod_{p|nm} \left(1 + \frac{1}{p}\right)^{-1} \quad &\text{if $mn$ is a perfect square,} \newline
 0 \quad &\text{otherwise,}
\end{cases}$$ 
which has the standard form of an orthogonality relation for characters. In the first case, $\chi_d(n) = 1$ unless $\gcd(d,n) > 1$, so essentially i'm trying to count fundamental discriminants. But this still seems a bit tricky to me. 
My approach is to try and count fundamental discriminants by using the generating function for squarefree numbers, i.e. $$\frac{\zeta(s)}{\zeta(2s)} = \sum_{n=1}^\infty \frac{|\mu(n)|}{n^s}.$$ I know that Jutila proves this in his paper On the Mean Values of $L(1/2,\chi_d)$ for Real Characters, but I would like to prove this lemma equation using analytic methods. Can anyone help me.  
 A: So I think I solved half of the problem. Suppose that $n$ is a perfect square. Then $\chi_d(n) = 1$ unless $\gcd(d,n) > 1$, in which case its $0$. So, for $\gcd{d,n} = 1$, we are simply pulling out the subset of fundamental discriminants having no common divisor with $n$. To quantify the size of this subset, we must first count fundamental discriminants.  
The set of fundamental discriminants consists of all square-free integers congruent to $1$ modulo $4$ (i.e. odd fundamental discriminants) and all such numbers multiplied by $-4$ and $\pm 8$ (i.e. even fundamental discriminants). The odd fundamental discriminants may be counted by considering the series $$\sum_{\text{$d$ odd}} \frac{1}{|d|^s}.$$ In fact, this is a Dirichlet series. For observe that $$\sum_{\text{$d$ odd}} \frac{1}{|d|^s} = 1 + \frac{1}{3^s} + \frac{1}{5^s} + \frac{1}{7^s} + \cdots =  \prod_{p>2} \left(1 + \frac{1}{p^s}\right) = \frac{\zeta(s)}{\zeta(2s)} \left(1 + \frac{1}{2^s}\right)^{-1},$$
where $$\frac{\zeta(s)}{\zeta(2s)} = \sum_{n=1}^\infty \frac{|\mu(n)|}{n^s},$$ is the Dirichlet series which generates the square-free numbers. So, by following the definition of fundamental discriminants given above, we can count fundamental discriminants by using the Dirichlet series $$\left(1 + \frac{1}{4^s} + \frac{2}{8^s}\right) \frac{\zeta(s)}{\zeta(2s)} \left(1 +\frac{1}{2^s}\right)^{-1} = \left(1 + \frac{1}{4^s} + \frac{2}{8^s}\right) \underbrace{\prod_{p>2} \left(1 + \frac{1}{p^s}\right)}_{l_p(s)}.$$ 
Now, to omit those discriminants with $\gcd(d,m) > 1$, we just omit the corresponding factors in $l_p(s)$. What's missing is $$\prod_{\substack{p>2 \\ p|m}} \left(1 + \frac{1}{p^s}\right),$$ so the relative density (compared to all fundamental discriminants $d$) is can be quantified by the expression $$\frac{1}{D} \cdot \prod_{\substack{p>2 \\ p\nmid m}} \left(1 + \frac{1}{p^s}\right) = \prod_{\substack{p>2 \\ p|m}} \left(1 + \frac{1}{p^s}\right)^{-1}.$$ As in the proof of the prime number theorem, the main contribution here comes from the simple pole at $s=1$ (of $\zeta(s)$). In fact, $p=2$ also fits at $s=1$ since $1 + \frac{1}{4} + \frac{2}{8} = 1 + \frac{1}{2}$. Thus, in the end we obtain $$\lim_{X\rightarrow \infty} \frac{1}{D} \sum_{0 < |d| \leq X} \chi_d(m) = \prod_{p|m} \left(1 + \frac{1}{p}\right)^{-1},$$ as desired.
Now, does anyone know how to explain the other case. I assume it just follows from the symmetry of the roots of unity. But can anyone validate and perhaps clarify this. Thank you.  
A: I'm not 100% sure I know what you mean by an "analytic proof" but I'll try to give an argument similar in style to what you already worked out.  In particular I won't go into any detail on the correspondence between average values of arithmetical functions, and the analytic behavior of the relevant generating Dirichlet series.
One annoying issue with fundamental discriminants is that they come in a few families and it is difficult to avoid case-by-case analysis.  For simplicity let's consider the case where $n$ is odd and squarefree, and $d$ runs over fundamental discriminants of the form $8c$ where $c$ is positive, odd, and squarefree.  The other cases are similar.
The goal is to show $$(1) \qquad \sum_{c \leq x}' (\frac{c}{n}) = o(x),$$ with the prime indicating $c$ is odd and squarefree, and where $(\frac{c}{n})$ is the Jacobi symbol.  The Dirichlet series $A_n(s) = \sum_{c}' (\frac{c}{n}) c^{-s}$ has the Euler product $A_n(s) = \prod_{p > 2}(1 + (\frac{p}{n}) p^{-s})$.  A simple calculation then shows $A_n(s) = L(s, \chi_n) \prod_{p \nmid 2n} (1-p^{-2s})$.  Here $L(s, \chi_n)$ is a primitive Dirichlet $L$-function that is entire.  In particular, there is no pole at $s=1$ so that (1) holds.
