結果

問題 No.2752 文字列の数え上げ mod 998244353
ユーザー NPNP
提出日時 2024-05-10 22:17:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 87,404 KB
最終ジャッジ日時 2024-12-20 05:56:46
合計ジャッジ時間 4,194 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def mod_exp(base, exp, mod):
    result = 1
    while exp > 0:
        if exp % 2 == 1:
            result = (result * base) % mod
        base = (base * base) % mod
        exp //= 2
    return result

def mod_inv(x, mod):
    return mod_exp(x, mod - 2, mod)

def compute_string_count(L):
    base = 26
    power = L + 1
    base_power_mod = mod_exp(base, power, MOD)
    inverse_25 = mod_inv(25, MOD)
    result = (base_power_mod - 1) * inverse_25 % MOD
    return result

T = int(input())
results = []

for i in range(T):
    L = int(input())
    results.append(str(compute_string_count(L) - 1))

print("\n".join(results))
0