#P16526. [THUPC 2026 决赛] 庆典门票
[THUPC 2026 决赛] 庆典门票
Background
From the finals of the 2026 Tsinghua University Student Programming Contest and Intercollegiate Invitational (THUPC2026).
Resources such as editorials can be found at https://github.com/dapingguo8/THUPC2026-final.
To celebrate the 10th anniversary of THUPC, Little T and Little S are preparing a grand 10th anniversary celebration.
The first step is to decide the main venue. They picked a room as the main venue and decorated it neatly with forest wallpaper, a huge garlic doll with no friends, a double "Xi" wall hanging (this year also happens to be Tsinghua's -th anniversary celebration), and feather ornaments. However, the hardworking Little T noticed a thorny problem—the room number on the doorplate in front of the main venue did not look neat enough. Little S timidly suggested that they could make the room number look neat by converting it to another base. During their attempts, they found that there was more than one base conversion scheme that could make the room number neat. So Little T and Little S decided to turn this interesting room-number design process into the entry challenge for the celebration, and let all participants solve it.
Problem Description
The main venue room number chosen by Little T and Little S is in decimal. Little T gives the following definition of a neat representation of the room number: for integers , if the base- representation of is formed by concatenating several blocks of length , where each block consists of the same digit, then is considered a neat representation.
Formally, let the base- representation of be . If there exists a positive integer such that the total number of digits , and for all it holds that , then is a neat representation.
For example, if the room number is or , then is a neat representation. If the room number is , then and are two different neat representations. If the room number is (whose hexadecimal representation is ), then is a neat representation.
To successfully win an entry ticket, you need to answer Little T and Little S's question: how many neat representations does the room number have in total?
Input Format
Each test point contains multiple groups of testdata. The first line contains a positive integer , denoting the number of test cases. For each test case:
- The first line contains a positive integer , denoting the room number of the main venue.
It is guaranteed that the sum of over all testdata does not exceed .
Output Format
For each test case, output one line with a non-negative integer, denoting the answer.
10
1
2
115
1111
2233
3355
191970
6737151
102934760424
618111100000
0
0
2
4
5
5
24
9
17
144
Hint
For the third test case, . The neat representations are and .
For the fourth test case, the neat representations are , , , and .
Translated by ChatGPT 5