#P5040. [SCOI2006] k进制集合的映射
[SCOI2006] k进制集合的映射
Description
Let be the set of all -digit base- integers (the most significant digit of may be ; for example, can be regarded as a -digit base- number or a -digit base- number. Under the conditions specified in the problem, it can be uniquely determined), where and . That is,
$$A(N,K)={a|a=a_1a_2a_3\cdots a_N,0≤a_i≤K-1,i=1,\cdots,N}$$Let be a subset of . It is the set of -digit base- integers generated from . The generation rule is as follows:
For any , there exists such that , where and . That is, is the smaller one of and .
Note 1: We call this rule a mapping from to , written as . It can be proven that this mapping is many-to-one. That is, if and , then for any elements satisfying and , we have .
Note 2: For some , is a proper subset of . For example, when , there does not exist any such that .
Task: Read two integers separated by a space from the input text file, and then output the value of the following expression to the specified output text file:
$$f(N,K)=\sum_{a\in A(N,K),Image(a)=d}(\prod_{i=1}^{N-1}(d_i+1))$$The expression above means: for all elements in , let its image be , add to each digit of , take the product, and then sum these products.
Where
$$\prod^{N-1}_{i=1}(d_i+1)=(d_1+1)(d_2+1)\cdots(d_{N-1}+1)$$Example: Let . Then , and the correct output should be .
Hint: You should first build a suitable method for computation. Directly computing using the expression of will cause most testdata to time out.
Input Format
The input file contains only one line: two integers and separated by a space.
Output Format
Output a single big integer, which is the computed result.
2 3
14
Hint
About the tests:
Full marks are given if the number is completely correct. When the number of digits of the output exceeds , if only the last two digits are incorrect, half of the score is given. (Each required result does not exceed .)
Translated by ChatGPT 5
京公网安备 11011102002149号