problem $0 - \cfrac 1 {0 - \cfrac 1 {0 - \cfrac 1 {\dots}}}$

Given an infinite sequence of nonnegative integers $a = (a_0, a_1, a_2, \dots)$ , we can form a negatively continued fraction
给一个长度无限的非负整数序列 $a = (a_0, a_1, a_2, \dots)$ ,我们可以构造一个负连分数:

We are interested in the case where the sequence $a$ is periodic, namely there exists $n \gt 0$ such that for all $k \ge 0$ . We write such a sequence as where $n$ is the minimal period.
我们对于数列 $a$ 是周期性的情况很感兴趣,即对于所有 $n \gt 0$ 存在 $n \gt 0$ 满足 .我们把这样 $n$ 是最小周期的序列 写下来.

As normal continued fractions, a negatively continued fraction may represent a real number. E.g. $N(\overline{2, 3})$ represents the number $\frac{3 + \sqrt 3}3 \approx 1.57735$ .
作为连分数,负连分数可以代表一个实数.例如 $N(\overline{2, 3})$ 代表数字 $\frac{3 + \sqrt 3}3 \approx 1.57735$ .

However, for some periodic sequences, the negatively continued fraction may even represent a complex number. E.g. $N(\overline{1, 4, 2})$ represents the number $\frac{9 + \sqrt{-3}}{14}$ .
然而对于某些周期数列,负连分数可以代表复数,例如 $N(\overline{1, 4, 2})$ 代表数字 $\frac{9 + \sqrt{-3}}{14}$ .

Moreover, the same complex number may be represented in different ways. E.g. $N(\overline{1, 5, 1, 3})$ also represents the number $\frac{9 + \sqrt{-3}}{14}$ .
此外,同一个复数可能有不同方式表示,例如 $N(\overline{1, 5, 1, 3})$ 也代表数字 $\frac{9 + \sqrt{-3}}{14}$ .

Let $Q(n)$ be the number of different periodic sequences $a$ such that $N(a)$ represents a complex number and the minimal period of $a$ does not exceed $n$ .
设 $Q(n)$ 为满足 $N(a)$ 为复数且最小周期不超过 $n$ 的数列 $a$ 的个数.

For example, $Q(1) = 2$ and $Q(2) = 6$ . In more details, there are two such sequences with minimal period $1$ , namely $\overline 0$ and $\overline 1$ , and there are four more such sequences with minimal period $2$ , namely $\overline{1, 2}$ , $\overline{2, 1}$ , $\overline{1, 3}$ , $\overline{3, 1}$ .
例如, $Q(1) = 2$ , $Q(2) = 6$ .具体地,有两个周期最小为 $1$ 的数列,分别是 $\overline 0$ 和 $\overline 1$ ,有四个最小周期为 $2$ 的数列,分别是 $\overline{1, 2}$ , $\overline{2, 1}$ , $\overline{1, 3}$ 和 $\overline{3, 1}$ .

Find $Q(12)$ .
求 $Q(12)$ .

题解(spoiler)

不会做(I don’t know).

首先观察样例,发现 N(|3|) 和 N(|2|) 最后都得到了x二次方的式子,所以推测 N(|12|) 也是x二次方的式子.

怎么推测ai的上界?