結果

問題 No.1253 雀見椪
ユーザー mkawa2mkawa2
提出日時 2021-09-05 18:50:20
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 919 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,204 KB
最終ジャッジ日時 2023-08-23 14:17:38
合計ジャッジ時間 10,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,080 KB
testcase_01 AC 17 ms
8,060 KB
testcase_02 AC 21 ms
8,064 KB
testcase_03 AC 79 ms
8,060 KB
testcase_04 AC 915 ms
8,048 KB
testcase_05 AC 915 ms
8,032 KB
testcase_06 AC 913 ms
8,080 KB
testcase_07 AC 914 ms
8,052 KB
testcase_08 AC 915 ms
8,204 KB
testcase_09 AC 919 ms
7,996 KB
testcase_10 AC 916 ms
8,168 KB
testcase_11 AC 917 ms
7,996 KB
testcase_12 AC 915 ms
8,132 KB
testcase_13 AC 916 ms
8,072 KB
testcase_14 AC 17 ms
8,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**20
# md = 998244353
md = 10**9+7

def solve():
    n, *ab = LI()
    ans = 1
    for i in range(0, 6, 2):
        a, b = ab[i], ab[i+1]
        p = a*pow(b, md-2, md)%md
        a, b = ab[i-2], ab[i-1]
        q = a*pow(b, md-2, md)%md
        if p*q:
            cur = (pow(q, n, md)*(pow((p+q)*pow(q, md-2, md), n, md)-1)-pow(p, n, md))%md
        else:
            cur=0
        ans -= cur
        ans %= md
    print(ans)

for _ in range(II()):
    solve()
0