結果

問題 No.3462 Buttons
コンテスト
ユーザー titia
提出日時 2026-06-20 03:45:37
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 959 ms / 2,000 ms
コード長 1,174 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 739 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2026-06-20 03:45:57
合計ジャッジ時間 17,713 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

mod=998244353

T=int(input())

for tests in range(T):
    A,B,K=list(map(int,input().split()))

    if B==0:
        ANS=max(0,A*K)
        print(ANS%mod)
        continue
    if A==0:
        print(0)
        continue

    if B==1:
        if A<0:
            ANS=0
        else:
            ANS=A*K

        print(ANS%mod)
        continue

    if B==-1:
        if A>0:
            ANS=A*K
        else:
            ANS=-A*(K-1)

        print(ANS%mod)
        continue

    if B>1:
        if A>0:
            ANS=A*pow(B,K-1,mod)%mod
            print(ANS%mod)
        else:
            ANS=0
            print(ANS%mod)
        continue

    if B<=-1:
        if A>0:
            if (K-1)%2==0 and K>=2:
                ANS=A*pow(B,K-1,mod)%mod
            elif (K-1)%2==1 and K>=3:
                ANS=(A+A)*pow(B,K-2,mod)%mod
            else:
                ANS=A*K
        else:
            if (K-1)%2==1 and K>=2:
                ANS=A*pow(B,K-1,mod)%mod
            elif (K-1)%2==0 and K>=3:
                ANS=(A+A)*pow(B,K-2,mod)%mod
            else:
                ANS=0

        print(ANS%mod)
            
        
0