A15796 | Minibuses on Venus (medium version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the medium version of the problem. The only difference between the three versions is the constraints on $n$ and $k$ . You can make hacks only if all versions of the problem are solved.
Maxim is a minibus driver on Venus.
To ride on Maxim's minibus, you need a ticket. Each ticket has a number consisting of $n$ digits. However, as we know, the residents of Venus use a numeral system with base $k$ , rather than the decimal system. Therefore, the ticket number can be considered as a sequence of $n$ integers from $0$ to $k-1$ , inclusive.
The residents of Venus consider a ticket to be lucky if there is a digit on it that is equal to the sum of the remaining digits, modulo $k$ . For example, if $k=10$ , then the ticket $7135$ is lucky because $7 + 1 + 5 \equiv 3 \pmod{10}$ . On the other hand, the ticket $7136$ is not lucky because no digit is equal to the sum of the others modulo $10$ .
Once, while on a trip, Maxim wondered: how many lucky tickets exist? At the same time, Maxim understands that this number can be very large, so he is interested only in the answer modulo some prime number $m$ .

Maxim is a minibus driver on Venus.
To ride on Maxim's minibus, you need a ticket. Each ticket has a number consisting of $n$ digits. However, as we know, the residents of Venus use a numeral system with base $k$ , rather than the decimal system. Therefore, the ticket number can be considered as a sequence of $n$ integers from $0$ to $k-1$ , inclusive.
The residents of Venus consider a ticket to be lucky if there is a digit on it that is equal to the sum of the remaining digits, modulo $k$ . For example, if $k=10$ , then the ticket $7135$ is lucky because $7 + 1 + 5 \equiv 3 \pmod{10}$ . On the other hand, the ticket $7136$ is not lucky because no digit is equal to the sum of the others modulo $10$ .
Once, while on a trip, Maxim wondered: how many lucky tickets exist? At the same time, Maxim understands that this number can be very large, so he is interested only in the answer modulo some prime number $m$ .

输入格式
The only line of the input contains three integers $n$ , $k$ and $m$ ( $1 \le n \le 10^{18}$ , $1 \le k \le 100$ , $10^8 \le m \le 10^9 + 7$ , $m$ is a prime number) — the number of digits on the ticket, the base of the numeral system on Venus, and the module for answer calculation.
输出格式
Print one integer — the number of lucky tickets modulo $m$ , i. e. the remainder after dividing the answer by $m$ .
输入输出样例
输入 #1
3 2 1000000007
输出 #1
4
输入 #2
3 4 1000000007
输出 #2
28
In the first example, there are only four lucky tickets: $000$ , $011$ , $101$ , and $110$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted