結果

問題 No.2007 Arbitrary Mod (Easy)
ユーザー Mat_hMat_h
提出日時 2023-03-05 10:55:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-09-18 01:30:38
合計ジャッジ時間 3,511 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def fast_exp_mod(k,n,MOD):
    import math
    
    ans = 1
    temp = k%MOD
    a = [temp]
    saidai = int(math.log2(n))+1
    
    for _ in range(saidai):
        temp = temp**2 % MOD
        a.append(temp)
        
    for i in range(saidai):
        if n & 1 << i:
            ans = ans*a[i] % MOD
    
    return ans

def Main():
    a,n=map(int,input().split())
    MOD=998244353
    print(MOD)
    print(fast_exp_mod(a,n,MOD))
    
Main()
0