結果

問題 No.2113 Distance Sequence 1.5
ユーザー タコイモタコイモ
提出日時 2022-10-28 23:57:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 71,384 KB
最終ジャッジ日時 2023-09-20 07:17:37
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,184 KB
testcase_01 AC 74 ms
71,332 KB
testcase_02 AC 80 ms
71,312 KB
testcase_03 AC 76 ms
71,184 KB
testcase_04 AC 76 ms
71,124 KB
testcase_05 AC 76 ms
71,284 KB
testcase_06 AC 75 ms
71,128 KB
testcase_07 AC 74 ms
70,960 KB
testcase_08 AC 75 ms
71,116 KB
testcase_09 AC 75 ms
71,124 KB
testcase_10 AC 75 ms
71,376 KB
testcase_11 AC 75 ms
71,276 KB
testcase_12 AC 76 ms
71,200 KB
testcase_13 AC 74 ms
71,244 KB
testcase_14 AC 75 ms
71,096 KB
testcase_15 AC 75 ms
71,032 KB
testcase_16 AC 77 ms
71,264 KB
testcase_17 AC 76 ms
71,180 KB
testcase_18 AC 79 ms
71,184 KB
testcase_19 AC 78 ms
71,384 KB
testcase_20 AC 76 ms
71,060 KB
testcase_21 AC 74 ms
71,204 KB
testcase_22 AC 76 ms
71,116 KB
testcase_23 AC 76 ms
71,244 KB
testcase_24 AC 78 ms
71,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K = map(int,input().split())
if K == 1:
  print(M)
  exit()
  
mod = 998244353
def pow_k(x, n,mod):
    """
    O(log n)
    """
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K*x) % mod
        x = (x*x) % mod
        n //= 2
    return (K * x)%mod
if M <= K:
  ans = pow_k(M,2*N,mod)
  print(ans)
else:
  ans = pow_k(K,2*N,mod)

  ss = pow_k(K-1,2*N,mod)
  
  print((ans+(M-K)*(ans-ss))%mod)
  
  
0