  We consider a two-dimensional bi-layered loop model with a certain interlayer
coupling and study its spectrum on a torus. Each layer consists of an $O(n)$
model on a honeycomb lattice with periodic boundary conditions; these layers
are stacked such that the links of the lattice intersect each other. A complex
Boltzmann weight $\lambda$ with unit modulus is assigned to each intersection
of two loops each from each layer. The model is reduced to an inhomogeneous
vertex model at a special point of parameters. The continuum partition function
is represented, based on the idea of the Coulomb gas, by a path integral over
two compact bosonic fields. The modular invariance of the partition function
follows naturally. Further, because of the topological nature of the interlayer
coupling, the fluctuation of loops decomposes into a local and a global part.
The existence of the latter leads to a sum over all the pairs of torus knots,
which can be Poisson ressummed by the M\"{o}bius inversion formula. This
reveals the operator content of the theory. The multiplicity of each operator
is explicitly given by a combination of two Ramanujan sums. We calculate each
scaling dimension as a function of $\lambda$. We present the flow of dimensions
which connects the decoupled-$O(1)$ models at $\lambda=1$ and the
layered-$O(1)$ model with the non-trivial coupling $\lambda=-1$. The lower
spectrum in the latter model is related to that of a known coset model.
