結果

問題 No.251 大きな桁の復習問題(1)
ユーザー lam6er
提出日時 2025-03-20 18:45:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 549 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,756 KB
実行使用メモリ 68,228 KB
最終ジャッジ日時 2025-03-20 18:45:11
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_zero(s):
    return all(c == '0' for c in s)

def str_mod(s, mod):
    result = 0
    for c in s:
        result = (result * 10 + int(c)) % mod
    return result

n_str = input().strip()
m_str = input().strip()

mod_p = 129402307
mod_euler = mod_p - 1

m_is_zero = is_zero(m_str)

if m_is_zero:
    print(1 % mod_p)
else:
    a = str_mod(n_str, mod_p)
    if a == 0:
        print(0)
    else:
        m_mod = str_mod(m_str, mod_euler)
        exp = m_mod if m_mod != 0 else mod_euler
        result = pow(a, exp, mod_p)
        print(result)
0