Hints: RReeppeettiittiioonn
A $(b,p)$-tidy number has base-$b$ length $L = k \cdot p$ and splits into $k$ blocks of $p$ equal digits. For a fixed base $b$, how can you check all valid $p$ from the digit array of $n$?
Answer to Hint 1: Expand $n$ in base $b$, store digits from least to most significant, let
len be the count. For each $p \ge 2$ with len % p == 0, verify that every block of $p$ consecutive digits is constant. Each valid $(b,p)$ contributes $1$ to the answer.
Answer to Hint 2: Naively looping $b$ up to $n$ is too slow. Note that if $b \le \lfloor\sqrt{n}\rfloor$, then the base-$b$ expansion has at least three digits, so you can afford to iterate $b$ only up to about $\sqrt{n}$ and expand $n$ in each base.
Answer to Hint 3: For larger $b$, the representation becomes very short. If there are only two digits and they are equal, write $n = d \cdot b + d = d(b+1)$ with $0 < d < b$. Solve for $b = n/d - 1$ using divisors $d$ of $n$, and only count pairs not already found for small $b$ (the code uses
b > limit_b with limit_b = min(n-1, floor(sqrt(n)))).
Answer to Hint 4: Edge cases: $n \le 2$ admit no valid $(b,p)$ with $b,p \ge 2$ in the model’s loop; output $0$. Be careful with integer square root bounds so you do not double-count.
Answer to Hint 5: Overall complexity is about $O(\sqrt{n} \cdot \log n)$ per test from small-$b$ expansions plus $O(\sqrt{n})$ divisor work for the two-digit case.