Editorial : RReeppeettiittiioonn
This editorial follows model_sol.cpp: count ordered pairs $(b,p)$ with $b,p \ge 2$ such that the base-$b$ expansion of $n$ has length divisible by $p$ and splits into blocks of $p$ equal digits.
For $b$ from $2$ up to $\min(n-1, \lfloor\sqrt{n}\rfloor)$:
- Write $n$ in base $b$ (repeated division), obtaining digit array
digits[0..len-1](least significant first). - For each $p \ge 2$ with
len % p == 0, split intolen/pblocks of length $p$ and check that within each block all digits match. - Count every passing $(b,p)$.
The square-root cap ensures this loop is fast enough.
When $b > \lfloor\sqrt{n}\rfloor$, the base-$b$ representation has length $2$: $n = d \cdot b + d = d(b+1)$ with digit $d$ repeated twice. Then $b = n/d - 1$, and we need $b \ge 2$ and $0 < d < b$.
Enumerate divisors $d$ of $n$ up to $\min(n-1, \lfloor\sqrt{n}\rfloor)$, set $b = n/d - 1$, and if $b$ is larger than the small-$b$ limit (so not already counted) and $d < b$, increment the answer.
If $n \le 2$, print $0$.
Per test case, $O(\sqrt{n} \cdot \log n)$ from base conversions plus $O(\sqrt{n})$ for divisor enumeration.