QOJ.ac

QOJ

時間限制: 2.5 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#17766. Festival Tickets

统计

The main venue room number determined by Xiao T and Xiao S is $n$ in decimal. Xiao T gives the following definition for a "neat" representation of a room number: for positive integers $b, p \ge 2$, if the base-$b$ representation of the room number $n$ consists exactly of several segments of length $p$ with identical digits concatenated together, then $(b, p)$ is considered a neat representation.

Formally, let the base-$b$ representation of $n$ be $d_{k-1}d_{k-2} \dots d_1d_0$. If there exists a positive integer $c$ such that the total number of digits $k = cp$, and for all $0 \le i < c$, it holds that $d_{ip} = d_{ip+1} = \dots = d_{(i+1)p-1}$, then $(b, p)$ is a neat representation.

For example, if the room number is $2233$ or $3355$, then $(10, 2)$ is a neat representation; if the room number is $1111$, then $(10, 2)$ and $(10, 4)$ are two different neat representations; if the room number is $6737151$ (which is $66CCFF$ in hexadecimal), then $(16, 2)$ is a neat representation.

To successfully win an entrance ticket, you need to answer Xiao T and Xiao S's question: how many neat representations exist for the main venue's room number?

Input

Each test case contains multiple test data. The first line contains a positive integer $T$ ($1 \le T \le 10^3$), representing the number of test cases. For each test case:

  • The first line contains a positive integer $n$ ($1 \le n \le 10^{12}$), representing the room number of the main venue.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^{12}$.

Output

For each test case, output a single non-negative integer on a line, representing the answer.

Examples

Input 1

10
1
2
115
1111
2233
3355
191970
6737151
102934760424
618111100000

Output 1

0
0
2
4
5
5
24
9
17
144

Note

For the third test case, $115 = (55)_{22} = (11)_{114}$, so all neat representations are $(22, 2)$ and $(114, 2)$.

For the fourth test case, all neat representations are $(10, 2), (10, 4), (100, 2), (1110, 2)$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download
#1571EditorialOpenNew Editorial for Problem #17766Anonymous2026-04-18 01:17:38View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.