問題一覧 > 通常問題

No.2007 Arbitrary Mod (Easy)

レベル : / AI推定難易度 : 235 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 305
作問者 : Kiri8128 / テスター : platinum
お気に入りにしたユーザー ProblemId : 8034 / 自分の提出
問題文最終更新日: 2022-05-07 02:01:31
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 352 (順位表) の他の問題:

Problem Statement

Output the remainder when $a^n$ is divided by $M$.

$a$ and $n$ are given as input, but you may choose any $M$ you like. However, $M$ must be an integer satisfying $10^7 \le M \le 10^{18}$.

Input

$a\ n$

[Constraints]

  • $a,\ n$ are integers
  • $2 \le a \le 1000$
  • $2 \le n \le 10^{18}$

Output

$M$
$ans$

On the $1$st line, output $M$. $M$ must be an integer satisfying $10^7 \le M \le 10^{18}$.
On the $2$nd line, output the answer to the problem $ans$, that is, the remainder when $a^n$ is divided by $M$.
Print a newline at the end.

You will get AC if, for the $M$ given on the $1$st line of your output, the remainder when $a^n$ is divided by $M$ matches the $ans$ given on the $2$nd line of your output.

Sample

Sample 1
Input
5 3
Output
998244353
125

You chose $998244353$ as your preferred $M$ and output it on the $1$st line.
You output $125$, the remainder when $5^{3} = 125$ is divided by $M$, on the $2$nd line.

Sample 2
Input
2 30
Output
10000000
3741824

You chose $M=10^7$ and output it on the $1$st line.
Since $2^{30} = 1073741824$, you can get AC by outputting $3741824$, the remainder when this is divided by $10^7$, on the $2$nd line.

Alternatively, for example, you can also get AC by outputting $1073741824$ on the $1$st line and $0$ on the $2$nd line.

Sample 3
Input
999 12345678987654321
Output
998244353
877641551

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。