No.1648 Sum of Powers
Problem Statement
You are given integers $A,B,P,Q$.
Here, suppose that there exist real numbers $X,Y$ satisfying the following.
- $X \leq Y$
- $X+Y=A$
- $X \times Y=B$
In this case, find $1$ integer $N$ between $2$ and $10^{18}$, inclusive, such that $X^N + Y^N \equiv P, X^{N-1} + Y^{N-1} \equiv Q\ (\mathrm{mod}\ 998244353 )$.
It is guaranteed that the input of this problem satisfies the following.
- $X,Y$ exist and are uniquely determined.
- For every integer $N$ greater than or equal to $1$, $X^N+Y^N$ is an integer.
- There exists an integer $N$ between $2$ and $10^{10}$, inclusive, that satisfies the condition.
Input
$A\ \ B\ \ P\ \ Q$
- $0 \leq A,B,P,Q < 998244353$
- All inputs are integers.
Output
Output $N$. If there are multiple solutions, you may output any of them.
Sample
Sample 1
Input
13 42 559 85
Output
3
We have $X=6,Y=7$. Therefore, $X^3+Y^3 \equiv 559 , X^2+Y^2 \equiv 85\ (\mathrm{mod}\ 998244353)$ holds.
Sample 2
Input
2 1 2 2
Output
1000000000000000000
We have $X=1,Y=1$, and for every integer $N$ greater than or equal to $1$, $X^N+Y^N \equiv 2\ (\mathrm{mod}\ 998244353)$ holds.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂