結果

問題 No.2798 Multiple Chain
ユーザー vwxyz
提出日時 2024-06-28 22:23:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,387 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 75,952 KB
最終ジャッジ日時 2024-06-28 22:23:19
合計ジャッジ時間 3,512 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict

def Miller_Rabin_Primality_Test(N):
    if N==1:
        return False
    NN=N-1
    NN=NN//(NN&-NN)
    if N<4759123141:
        lst=[2,7,61]
    elif N<341550071728321:
        lst=[2,3,5,7,11,13,17]
    else:
        lst=[2,3,5,7,11,13,17,19,23,29,31,37]
    if N in lst:
        return True
    for a in lst:
        n=NN
        p=pow(a,n,N)
        if p==1:
            continue
        while p!=N-1:
            p=p*p%N
            if p==1 or n==N-1:
                return False
            n<<=1
    return True

def Pollard_Rho(N):
    if N==1:
        return None
    if Miller_Rabin_Primality_Test(N):
        return None
    m=1<<N.bit_length()//8
    for c in range(1,99):
        f=lambda x:(x**2+c)%N
        y,r,q,g=2,1,1,1
        while g==1:
            x=y
            for _ in range(r):
                y=f(y)
            k=0
            while k<r and g==1:
                ys=y
                for _ in range(min(m,r-k)):
                    y=f(y)
                    q=q*abs(x-y)%N
                g=math.gcd(q,N)
                k+=m
            r<<=1
        if g==N:
            g=1
            while g==1:
                ys=f(ys)
                g=math.gcd(abs(x-ys),N)
        if g<N:
            return g

def Factorize_Pollard_Rho(N):
    stack=[N]
    factorize=defaultdict(int)
    while stack:
        x=stack.pop()
        p=Pollard_Rho(x)
        if p==None:
            factorize[x]+=1
            continue
        stack.append(p)
        stack.append(x//p)
    return factorize

def Divisors_Pollard_Rho(N):
    factorize=Factorize_Pollard_Rho(N)
    divisors=[1]
    for p,e in factorize.items():
        prev=divisors
        divisors=[]
        pow_p=1
        for _ in range(e+1):
            for d in prev:
                divisors.append(d*pow_p)
            pow_p*=p
    divisors.sort()
    return divisors

C=[1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490, 627, 792, 1002, 1255, 1575, 1958, 2436, 3010, 3718, 4565, 5604, 6842, 8349, 10143, 12310, 14883, 17977, 21637, 26015, 31185, 37338, 44583, 53174, 63261, 75175, 89134, 105558, 124754, 147273, 173525,204226,239943,281589,329931,386155,451276,526823,614154,715220,831820,966467,1121505,1300156,1505499,1741630]

N=int(input())
ans=1
for p,e in Factorize_Pollard_Rho(N).items():
    ans*=C[e]
print(ans)
0