結果

問題 No.2480 Sequence Sum
ユーザー 👑 rin204rin204
提出日時 2023-09-23 02:02:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 500 ms
コード長 1,859 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 75,748 KB
最終ジャッジ日時 2023-10-04 12:35:05
合計ジャッジ時間 2,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,484 KB
testcase_01 AC 71 ms
71,680 KB
testcase_02 AC 74 ms
71,548 KB
testcase_03 AC 73 ms
71,344 KB
testcase_04 AC 72 ms
71,752 KB
testcase_05 AC 72 ms
71,512 KB
testcase_06 AC 73 ms
71,720 KB
testcase_07 AC 76 ms
71,488 KB
testcase_08 AC 73 ms
71,584 KB
testcase_09 AC 74 ms
71,208 KB
testcase_10 AC 73 ms
71,288 KB
testcase_11 AC 73 ms
71,760 KB
testcase_12 AC 73 ms
71,212 KB
testcase_13 AC 74 ms
71,584 KB
testcase_14 AC 76 ms
75,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd


def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1

    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True


def pollard(n):
    if n % 2 == 0:
        return 2
    if isprime(n):
        return n

    f = lambda x: (x * x + 1) % n

    step = 0
    while 1:
        step += 1
        x = step
        y = f(x)
        while 1:
            p = gcd(y - x + n, n)
            if p == 0 or p == n:
                break
            if p != 1:
                return p
            x = f(x)
            y = f(f(y))


def primefact(n):
    if n == 1:
        return []
    p = pollard(n)
    if p == n:
        return [p]
    left = primefact(p)
    right = primefact(n // p)
    left += right
    return sorted(left)


def primedict(n):
    P = primefact(n)
    ret = {}
    for p in P:
        ret[p] = ret.get(p, 0) + 1
    return ret


def divisor_lst(n):
    if n == 1:
        return [1]
    primes = primefact(n)
    primes.append(primes[-1] + 1)
    bef = primes[0]
    cnt = 0
    ret = [1]
    for p in primes:
        if p == bef:
            cnt += 1
        else:
            times = bef
            le = len(ret)
            for _ in range(cnt):
                for i in range(le):
                    ret.append(ret[i] * times)
                times *= bef
            bef = p
            cnt = 1
    ret.sort()
    return ret


n = int(input())
print(n - len(divisor_lst(n)))
0