Codeforces Round 460 (Div. 2)
E
Congruence Equation
Codeforces
2100
原题
← DF →
翻译中…

Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.

翻译中…

Input

翻译中…

The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b \lt p$, $1 \leq x \leq 10^{12}$). It is guaranteed that $p$ is a prime.

翻译中…

Output

翻译中…

Print a single integer: the number of possible answers $n$.

翻译中…

Note

翻译中…

In the first sample, we can see that $n=2$ and $n=8$ are possible answers.

翻译中…

样例

Input #1
2 3 5 8
Output #1
2
InputCopy OutputCopy
Input #2
4 6 7 13
Output #2
1
InputCopy OutputCopy
Input #3
233 233 10007 1
Output #3
1
InputCopy OutputCopy
题目信息
题号
919E
时间限制
3 s
内存限制
256 MB
标签
中国剩余定理
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。