問題一覧 > 通常問題

No.1648 Sum of Powers

レベル : / AI推定難易度 : 2225 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 23
作問者 : 蜜蜂 / テスター : Mitarushi ygussany
お気に入りにしたユーザー ProblemId : 6790 / 自分の提出
問題文最終更新日: 2021-08-05 10:51:50
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 309 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。