結果

問題 No.1844 Divisors Sum Sum
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-15 15:39:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 1,170 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 95,244 KB
最終ジャッジ日時 2023-10-18 12:25:22
合計ジャッジ時間 12,269 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 531 ms
94,808 KB
testcase_01 AC 557 ms
95,244 KB
testcase_02 AC 558 ms
95,244 KB
testcase_03 AC 558 ms
95,240 KB
testcase_04 AC 561 ms
95,244 KB
testcase_05 AC 558 ms
95,096 KB
testcase_06 AC 559 ms
95,236 KB
testcase_07 AC 561 ms
95,096 KB
testcase_08 AC 561 ms
94,940 KB
testcase_09 AC 560 ms
95,096 KB
testcase_10 AC 516 ms
91,584 KB
testcase_11 AC 165 ms
81,712 KB
testcase_12 AC 405 ms
89,176 KB
testcase_13 AC 119 ms
78,424 KB
testcase_14 AC 228 ms
84,116 KB
testcase_15 AC 43 ms
55,656 KB
testcase_16 AC 43 ms
55,656 KB
testcase_17 AC 42 ms
55,656 KB
testcase_18 AC 42 ms
55,656 KB
testcase_19 AC 43 ms
55,656 KB
testcase_20 AC 42 ms
55,656 KB
testcase_21 AC 43 ms
55,656 KB
testcase_22 AC 43 ms
55,656 KB
testcase_23 AC 43 ms
55,656 KB
testcase_24 AC 43 ms
55,656 KB
testcase_25 AC 42 ms
55,656 KB
testcase_26 AC 43 ms
55,656 KB
testcase_27 AC 43 ms
55,656 KB
testcase_28 AC 42 ms
55,656 KB
testcase_29 AC 43 ms
55,656 KB
testcase_30 AC 43 ms
55,656 KB
testcase_31 AC 43 ms
55,656 KB
testcase_32 AC 43 ms
55,656 KB
testcase_33 AC 43 ms
55,656 KB
testcase_34 AC 43 ms
55,656 KB
testcase_35 AC 43 ms
55,656 KB
testcase_36 AC 42 ms
55,656 KB
testcase_37 AC 43 ms
55,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from math import floor

MOD = int(1e9 + 7)


def getPrimeFactors(n: int) -> Counter:
    """返回 n 的所有质数因子"""
    res = Counter()
    upper = floor(n**0.5) + 1
    for i in range(2, upper):
        while n % i == 0:
            res[i] += 1
            n //= i

    # 注意考虑本身
    if n > 1:
        res[n] += 1
    return res


def sumOfFactors(counter: "Counter[int]") -> int:
    """返回所有约数之和, counter 为这个数的所有质数因子分解."""
    res = 1
    for p, count in counter.items():
        inv = pow(p - 1, MOD - 2, MOD)
        tmp = inv * (inv * (pow(p, count + 2, MOD) - 1) - (count + 2)) % MOD
        res = res * tmp % MOD
    return res


def countOfFactors(counter: "Counter[int]") -> int:
    """返回所有约数个数, counter 为这个数的所有质数因子分解."""
    res = 1
    for count in counter.values():
        res *= count + 1
        res %= MOD
    return res


if __name__ == "__main__":
    n = int(input())
    counter = Counter()
    for _ in range(n):
        p, c = map(int, input().split())
        counter[p] += c
    print(sumOfFactors(counter))
0