結果

問題 No.147 試験監督(2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-04 17:54:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,108 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 78,944 KB
最終ジャッジ日時 2023-09-25 01:06:05
合計ジャッジ時間 5,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,108 ms
78,808 KB
testcase_01 AC 1,097 ms
78,692 KB
testcase_02 AC 1,097 ms
78,944 KB
testcase_03 AC 70 ms
71,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(c, d, mod, memo):
    return pow(g(c, mod, memo), d, mod)

def g(c, mod, memo):
    p, q = 1, 1
    i = 0
    while c:
        if c & 1:
            a, b = memo[i]
            tmp = p - q
            p = (a*q + b*tmp) % mod
            q = (a*tmp - b*(tmp - q)) % mod
        c >>= 1
        i += 1
    return p

def preprocess(c, mod):
    a, b = 2, 1
    memo = [(2, 1)]
    while c:
        t = a - b
        t *= t
        a *= a
        a -= t
        a %= mod
        b *= b
        b += t
        b %= mod
        c >>= 1
        memo.append((a, b))
    return memo

def solve():
    mod = 10**9 + 7
    memo = preprocess(10**18, mod)
    N = int(input())
    ans = 1
    for n in range(N):
        c, d = map(int, input().split())
        ans *= f(c, d, mod, memo)
        ans %= mod
    return ans

print(solve())
0