結果
| 問題 | No.3462 Buttons |
| コンテスト | |
| ユーザー |
koheijkt
|
| 提出日時 | 2026-02-28 16:09:49 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,065 bytes |
| 記録 | |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 77,772 KB |
| 実行使用メモリ | 237,864 KB |
| 最終ジャッジ日時 | 2026-02-28 16:10:01 |
| 合計ジャッジ時間 | 4,833 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | TLE * 1 -- * 14 |
ソースコード
import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 1e18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def I(): return input().rstrip()
def II(): return int(input().rstrip())
def IS(): return input().rstrip().split()
def MII(): return map(int, input().rstrip().split())
def LI(): return list(input().rstrip())
def TII(): return tuple(map(int, input().rstrip().split()))
def LII(): return list(map(int, input().rstrip().split()))
def LSI(): return list(map(str, input().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
T = II()
for i in range(T):
A, B, K = MII()
if A > 0:
if -1 <= B <= 1:
ans = A*K
ans %= MOD
elif B >= 2:
ans = A * pow(B, (K - 1)%(MOD - 1), MOD)
ans %= MOD
else: # + で終わるように調整
nokori = K - 1
if nokori%2 != 0:
nokori -= 1
ans = A * pow(abs(B), nokori%(MOD - 1), MOD)
ans %= MOD
elif A == 0:
ans = 0
else: # A < 0
if B >= 0:
# 好転しない
ans = 0
elif B == -1:
ans = A*(K - 1) * (-1)
else:
ans1 = A*(K - 1) * B
nokori = K - 1
if nokori%2 != 1:
nokori -= 1
#ans2 = A * B**(nokori)
ans2 = A
# ans1 を超えるのに何回かかるか確認する
cnt = 0
while ans2 < ans1:
ans2 *= abs(B)
cnt += 1
if cnt < nokori: # ans2 が ans1 を超える
ans = A* pow(abs(B), nokori%(MOD - 1), MOD)
ans %= MOD
else:
ans = ans1%MOD
print(ans)
koheijkt