結果

問題 No.1844 Divisors Sum Sum
ユーザー lloyz
提出日時 2022-02-18 23:31:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 918 ms / 3,000 ms
コード長 758 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,568 KB
最終ジャッジ日時 2024-06-29 09:55:35
合計ジャッジ時間 15,007 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

n = int(input())
mod = 10**9 + 7
ans = 1
for _ in range(n):
    p, e = map(int, input().split())
    temp1 = (e + 1) * (pow(p, e + 1, mod) - 1) % mod
    temp1 *= modinv(p - 1, mod)
    temp1 %= mod
    temp2 = 1 - ((e + 1) * pow(p, e, mod) % mod) + (e * pow(p, e + 1, mod) % mod)
    temp2 %= mod
    temp2 *= modinv((p - 1)**2, mod) * p % mod
    temp2 %= mod
    ans *= (temp1 - temp2) % mod
    ans %= mod
print(ans)
0