302574: CF497E. Subsequences Return
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Subsequences Return
题意翻译
设 $s_k(x)$ 表示 $x$ 在 $k$ 进制下各位数的和 $\bmod k$ 的值。给出 $k$,现有序列 $[s_k(0),s_k(1),\ldots, s_k(n-1)]$。 求这个序列有多少个本质不同的子序列。 $n\leq 10^{18},k\leq 30$。题目描述
Assume that $ s_{k}(n) $ equals the sum of digits of number $ n $ in the $ k $ -based notation. For example, $ s_{2}(5)=s_{2}(101_{2})=1+0+1=2 $ , $ s_{3}(14)=s_{3}(112_{3})=1+1+2=4 $ . The sequence of integers $ a_{0},...,a_{n-1} $ is defined as ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF497E/6cf1a2e064eafad1586b721275139d1721b088bf.png). Your task is to calculate the number of distinct subsequences of sequence $ a_{0},...,a_{n-1} $ . Calculate the answer modulo $ 10^{9}+7 $ . Sequence $ a_{1},...,a_{k} $ is called to be a subsequence of sequence $ b_{1},...,b_{l} $ , if there is a sequence of indices $ 1<=i_{1}<...<i_{k}<=l $ , such that $ a_{1}=b_{i1} $ , ..., $ a_{k}=b_{ik} $ . In particular, an empty sequence (i.e. the sequence consisting of zero elements) is a subsequence of any sequence.输入输出格式
输入格式
The first line contains two space-separated numbers $ n $ and $ k $ ( $ 1<=n<=10^{18} $ , $ 2<=k<=30 $ ).
输出格式
In a single line print the answer to the problem modulo $ 10^{9}+7 $ .
输入输出样例
输入样例 #1
4 2
输出样例 #1
11
输入样例 #2
7 7
输出样例 #2
128