結果

問題 No.1127 変形パスカルの三角形
ユーザー lloyzlloyz
提出日時 2022-07-18 00:47:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 1,500 ms
コード長 684 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 82,172 KB
最終ジャッジ日時 2023-09-12 12:50:40
合計ジャッジ時間 5,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,284 KB
testcase_01 AC 110 ms
81,056 KB
testcase_02 AC 98 ms
81,612 KB
testcase_03 AC 96 ms
80,388 KB
testcase_04 AC 86 ms
77,152 KB
testcase_05 AC 93 ms
80,004 KB
testcase_06 AC 103 ms
80,868 KB
testcase_07 AC 90 ms
78,672 KB
testcase_08 AC 90 ms
78,372 KB
testcase_09 AC 98 ms
80,292 KB
testcase_10 AC 99 ms
80,256 KB
testcase_11 AC 99 ms
81,996 KB
testcase_12 AC 101 ms
81,452 KB
testcase_13 AC 98 ms
81,012 KB
testcase_14 AC 94 ms
80,244 KB
testcase_15 AC 88 ms
78,376 KB
testcase_16 AC 97 ms
80,584 KB
testcase_17 AC 89 ms
78,476 KB
testcase_18 AC 99 ms
80,864 KB
testcase_19 AC 101 ms
81,944 KB
testcase_20 AC 103 ms
82,068 KB
testcase_21 AC 103 ms
82,156 KB
testcase_22 AC 90 ms
78,540 KB
testcase_23 AC 101 ms
80,124 KB
testcase_24 AC 97 ms
80,392 KB
testcase_25 AC 99 ms
80,648 KB
testcase_26 AC 97 ms
81,164 KB
testcase_27 AC 98 ms
81,712 KB
testcase_28 AC 101 ms
81,584 KB
testcase_29 AC 88 ms
78,304 KB
testcase_30 AC 86 ms
77,504 KB
testcase_31 AC 102 ms
82,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b = map(int, input().split())
n, k = map(int, input().split())
mod = 10**9 + 7
a %= mod
b %= mod

fact = [1] * n
inv = [1] * n
finv = [1] * n
for i in range(2, n):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod
def comb(x, y):
    if x < 0 or y < 0 or x - y < 0:
        return 0
    return fact[x] * finv[y] % mod * finv[x - y] % mod

res = comb(n - 1, k - 1) * a % mod + comb(n - 1, k - 2) * b % mod
print(res % mod)
ans = pow(a, 2, mod) + pow(b, 2, mod) % mod
for i in range(2, n + 1):
    ans += pow(comb(n - 1, i - 1) * a % mod + comb(n - 1, i - 2) * b % mod, 2, mod)
    ans %= mod
print(ans)

0