INFINITE-DIMENSIONAL GENERALIZED CONTINUED FRACTIONS, DISTRIBUTION OF QUADRATIC RESIDUES AND NON-RESIDUES, AND ERGODIC THEORY