A8478 | Visit of the Great
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Great Mushroom King descended to the dwarves, but not everyone managed to see him. Only the few chosen ones could see the King.
We know that only $LCM(k^{2^l}+1,k^{2^{l+1}}+1,...,k^{2^r}+1)$ dwarves can see the Great Mushroom King. Numbers $k$ , $l$ , $r$ are chosen by the Great Mushroom King himself in some complicated manner which is unclear to common dwarves.
The dwarven historians decided to document all visits of the Great Mushroom King. For each visit the dwarven historians know three integers $k_{i}$ , $l_{i}$ , $r_{i}$ , chosen by the Great Mushroom King for this visit. They also know a prime number $p_{i}$ . Help them to count the remainder of dividing the number of dwarves who can see the King, by number $p_{i}$ , for each visit.
We know that only $LCM(k^{2^l}+1,k^{2^{l+1}}+1,...,k^{2^r}+1)$ dwarves can see the Great Mushroom King. Numbers $k$ , $l$ , $r$ are chosen by the Great Mushroom King himself in some complicated manner which is unclear to common dwarves.
The dwarven historians decided to document all visits of the Great Mushroom King. For each visit the dwarven historians know three integers $k_{i}$ , $l_{i}$ , $r_{i}$ , chosen by the Great Mushroom King for this visit. They also know a prime number $p_{i}$ . Help them to count the remainder of dividing the number of dwarves who can see the King, by number $p_{i}$ , for each visit.
输入格式
The first line contains the single integer $t$ $(1<=t<=10^{5})$ — the number of the King's visits.
Each of the following $t$ input lines contains four space-separated integers $k_{i}$ , $l_{i}$ , $r_{i}$ and $p_{i}$ $(1<=k_{i}<=10^{6}$ ; $0<=l_{i}<=r_{i}<=10^{18}; 2<=p_{i}<=10^{9})$ — the numbers, chosen by the Great Mushroom King and the prime module, correspondingly.
It is guaranteed that for all visits number $p_{i}$ is prime.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Each of the following $t$ input lines contains four space-separated integers $k_{i}$ , $l_{i}$ , $r_{i}$ and $p_{i}$ $(1<=k_{i}<=10^{6}$ ; $0<=l_{i}<=r_{i}<=10^{18}; 2<=p_{i}<=10^{9})$ — the numbers, chosen by the Great Mushroom King and the prime module, correspondingly.
It is guaranteed that for all visits number $p_{i}$ is prime.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出格式
For each visit print the answer on a single line — the remainder of dividing the number of the dwarves who can see the King this time, by number $p_{i}$ . Print the answers for the visits in the order, in which the visits are described in the input.
输入输出样例
输入 #1
2 3 1 10 2 5 0 4 3
输出 #1
0 0
We consider that $LCM(a_{1},a_{2},...,a_{n})$ represents the least common multiple of numbers $a_{1}$ , $a_{2}$ , $...$ , $a_{n}$ .
We consider that $x^{0}=1$ , for any $x$ .
We consider that $x^{0}=1$ , for any $x$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted