結果

問題 No.147 試験監督(2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-06-11 00:22:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 821 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-09-20 20:42:32
合計ジャッジ時間 13,243 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 15 ms
7,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def g(c, mod):
    ''' 長さ c の机に一人あけて座るパターン数を mod で除した余り。
    g(c) = g(c-1) + g(c-2)
    g(0) = 1
    g(1) = 2
    g(2) = 3
    フィボナッチ数列を求めるのと同じ。
    '''
    p, q = 1, 1
    a, b = 2, 1
    while c:
        if c & 1:
            tmp = p - q
            p = (a*q + b*tmp) % mod
            q = (a*tmp - b*(tmp - q)) % mod
        t = a - b
        t *= t
        a *= a
        a -= t
        a %= mod
        b *= b
        b += t
        b %= mod
        c >>= 1
    return p

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

print(solve())
0