結果

問題 No.3462 Buttons
コンテスト
ユーザー tyawanmusi
提出日時 2026-02-27 10:17:25
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 704 ms / 2,000 ms
+ 247µs
コード長 883 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 630 ms
コンパイル使用メモリ 14,720 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2026-10-22 08:11:15
合計ジャッジ時間 14,377 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
for _ in range(int(input())):
    a, b, k = map(int, input().split())
    mod = 998244353
    if b == 1 or b == 0:
        print(max(a, 0) * k % mod)
        continue
    if b == -1:
        if a >= 0:
            print(a * k % mod)
        else:
            print(- a * (k - 1) % mod)
        continue
    if a < 0:
        if b > 0:
            print(0)
        else:
            if k == 1:
                print(0)
            else:
                if k % 2 == 0:
                    print(- a * pow(-b, k-1, mod) % mod)
                else:
                    print(- 2 * a * pow(-b, k-2, mod) % mod)
    else:
        if b > 0:
            print(a * pow(b, k-1, mod) % mod)
        else:
            if k % 2 == 0:
                print(2 * a * pow(-b, k-2, mod) % mod)
            else:
                print(a * pow(-b, k-1, mod) % mod)
0