結果

問題 No.1737 One to N
ユーザー hiragnhiragn
提出日時 2022-11-03 01:28:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 9,276 KB
最終ジャッジ日時 2023-09-24 12:05:28
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
9,200 KB
testcase_01 AC 22 ms
9,108 KB
testcase_02 AC 23 ms
9,084 KB
testcase_03 AC 22 ms
9,060 KB
testcase_04 AC 22 ms
9,248 KB
testcase_05 AC 22 ms
9,180 KB
testcase_06 AC 23 ms
9,212 KB
testcase_07 AC 23 ms
9,180 KB
testcase_08 AC 23 ms
9,276 KB
testcase_09 AC 21 ms
9,064 KB
testcase_10 AC 22 ms
9,092 KB
testcase_11 AC 22 ms
9,196 KB
testcase_12 AC 22 ms
9,060 KB
testcase_13 AC 22 ms
9,064 KB
testcase_14 AC 24 ms
9,064 KB
testcase_15 AC 23 ms
9,144 KB
testcase_16 AC 22 ms
9,116 KB
testcase_17 AC 22 ms
9,124 KB
testcase_18 AC 24 ms
9,116 KB
testcase_19 AC 21 ms
9,248 KB
testcase_20 AC 22 ms
9,060 KB
testcase_21 AC 22 ms
9,200 KB
testcase_22 AC 22 ms
9,276 KB
testcase_23 AC 22 ms
9,248 KB
testcase_24 AC 22 ms
9,056 KB
testcase_25 AC 22 ms
9,228 KB
testcase_26 AC 22 ms
9,208 KB
testcase_27 AC 22 ms
9,216 KB
testcase_28 AC 22 ms
9,080 KB
testcase_29 AC 22 ms
9,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict


def is_prime(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True


def prime_fact(n):
    res = defaultdict(int)
    if n == 1:
        return res
    p = 2
    while p <= 10 ** 4 and n > 1:
        if n % p == 0:
            while n % p == 0:
                res[p] += 1
                n //= p
        p += 1
    while n > 1:
        if is_prime(n):
            res[n] += 1
            break
        x = random.randrange(n)
        y = (x * x + 1) % n
        i = 1
        while True:
            d = gcd(abs(x - y), n)
            if d == 1:
                i += 1
            elif d == n:
                res[n] += 1
                return res
            else:
                res[d] += 1
                n //= d
                break
            x = (x * x + 1) % n
            y = (y * y + 1) % n
            y = (y * y + 1) % n
    return res


def main():
    n = int(input())
    ans = sum([x * y for x, y in prime_fact(n).items()])
    print(ans)


if __name__ == "__main__":
    main()
0