luogu#P4973. 毒瘤之神奇进制
毒瘤之神奇进制
Background
hsl2363 is building a computer.
Problem Description
hsl2363 found computers very fun, so he plans to build one himself. After he finishes it, zrz_orz comes. hsl2363 tells him:
“My computer uses the ‘-* base’. I really want to know how weak you are, so I’m asking you what these numbers become after converting to decimal.”
A number written in “-* base” can be made of ASCII visible characters (excluding characters whose ASCII code is ). Let an “-* base” string have length , with digit positions numbered from right to left as to . The value it represents is the product over all positions: take the ASCII code of the character at position , subtract the ASCII code of 0 (i.e., ), and multiply by , then multiply all these terms together. That is,
where denotes the ASCII code value of character x.
Here is an example:
If and 2363,
then
$\begin{aligned} s&= f('2') \times 3^3 \times f('3') \times 3 ^ 2 \times f('6') \times 3 ^ 1 \times f('3') \times 3 ^ 0 \\ &= 2 \times 3^3 \times 3 \times 3 ^ 2 \times 6 \times 3 ^ 1 \times 3 \times 3 ^ 0\\ &= 78732 \end{aligned}$
zrz_orz thinks it is too hard, so he throws the problem to you. Now there are numbers written in “-* base” (different numbers may have different ). You need to find their decimal representations.
Because the answer may be very large, output the length of the answer.
Input Format
The first line contains an integer .
The next lines: the -th line contains an integer and a string , meaning the -th number is in “-* base”, and its representation in that base is .
Output Format
Output lines.
The -th line contains one integer, the length of the -th number’s decimal representation.
1
1 11
1
1
2 a45
4
Hint
【Constraints】
For of the testdata, .
ASCII visible characters (excluding characters whose ASCII code is ) include the following characters (sorted in increasing ASCII code):
123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
【Hint】
If you want to brute force it, it is impossible without big integers.
Translated by ChatGPT 5