結果

問題 No.1312 Snake Eyes
ユーザー 👑 KazunKazun
提出日時 2021-02-16 04:39:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,292 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 82,048 KB
最終ジャッジ日時 2023-10-01 02:01:50
合計ジャッジ時間 15,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,596 KB
testcase_01 AC 70 ms
71,484 KB
testcase_02 AC 70 ms
71,400 KB
testcase_03 AC 69 ms
71,536 KB
testcase_04 AC 75 ms
71,488 KB
testcase_05 AC 70 ms
71,480 KB
testcase_06 AC 73 ms
71,488 KB
testcase_07 AC 72 ms
71,440 KB
testcase_08 AC 71 ms
71,640 KB
testcase_09 AC 69 ms
71,400 KB
testcase_10 AC 69 ms
71,216 KB
testcase_11 AC 69 ms
71,400 KB
testcase_12 AC 71 ms
71,716 KB
testcase_13 AC 71 ms
71,376 KB
testcase_14 AC 72 ms
71,444 KB
testcase_15 AC 73 ms
71,496 KB
testcase_16 AC 72 ms
71,412 KB
testcase_17 AC 73 ms
71,252 KB
testcase_18 AC 72 ms
71,384 KB
testcase_19 AC 76 ms
71,340 KB
testcase_20 AC 70 ms
71,492 KB
testcase_21 AC 73 ms
71,252 KB
testcase_22 AC 72 ms
71,304 KB
testcase_23 AC 74 ms
71,336 KB
testcase_24 AC 73 ms
71,256 KB
testcase_25 AC 73 ms
71,584 KB
testcase_26 AC 70 ms
71,492 KB
testcase_27 AC 72 ms
71,368 KB
testcase_28 AC 71 ms
71,532 KB
testcase_29 AC 71 ms
71,608 KB
testcase_30 AC 73 ms
71,376 KB
testcase_31 AC 74 ms
71,344 KB
testcase_32 AC 73 ms
71,248 KB
testcase_33 AC 73 ms
71,632 KB
testcase_34 AC 71 ms
71,400 KB
testcase_35 AC 71 ms
71,376 KB
testcase_36 AC 72 ms
71,400 KB
testcase_37 AC 72 ms
71,540 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 AC 69 ms
71,300 KB
testcase_64 RE -
testcase_65 RE -
testcase_66 AC 71 ms
71,480 KB
testcase_67 AC 71 ms
71,588 KB
testcase_68 RE -
testcase_69 AC 71 ms
71,496 KB
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 AC 73 ms
71,500 KB
testcase_75 AC 73 ms
71,652 KB
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ポラード・ローアルゴリズムによって素因数を発見する
#参考元:https://judge.yosupo.jp/submission/6131
def Find_Factor_Rho(N):
    if N==1:
        return 1
    from math import gcd
    m=1<<(N.bit_length()//8+1)

    for c in range(1,99):
        f=lambda x:(x*x+c)%N
        y,r,q,g=2,1,1,1
        while g==1:
            x=y
            for i in range(r):
                y=f(y)
            k=0
            while k<r and g==1:
                for i in range(min(m, r - k)):
                    y=f(y)
                    q=q*abs(x - y)%N
                g=gcd(q,N)
                k+=m
            r <<=1

        if g<N:
            if Miller_Rabin_Primality_Test(g):
                return g
            elif Miller_Rabin_Primality_Test(N//g):
                return N//g
    return N

#ポラード・ローアルゴリズムによる素因数分解
#参考元:https://judge.yosupo.jp/submission/6131
def Pollard_Rho_Prime_Factorization(N):
    I=2
    res=[]
    while I*I<=N:
        if N%I==0:
            k=0
            while N%I==0:
                k+=1
                N//=I
            res.append([I,k])

        I+=1+(I%2)

        if I!=101 or N<2**20:
            continue

        while N>1:
            if Miller_Rabin_Primality_Test(N):
                res.append([N,1])
                N=1
            else:
                j=Find_Factor_Rho(N)
                k=0
                while N%j==0:
                    N//=j
                    k+=1
                res.append([j,k])
    if N>1:
        res.append([N,1])
    res.sort(key=lambda x:x[0])
    return res

def integer_product(T):
    a=1
    for t in T:
        a*=t
    return a

from itertools import product
def divisors(X):
    E=[[pow(p,k) for k in range(e+1)] for p,e in X]
    A=[integer_product(t) for t in product(*E)]
    A.sort()
    return A

def check(N,r):
    p=N%r
    while N:
        if N%r!=p:
            return False
        N//=r
    return True
#================================================
N=int(input())
Y=Pollard_Rho_Prime_Factorization(N)
D=divisors(Y)

X=N+1
for a in D:
    M=N//a

    Y=Pollard_Rho_Prime_Factorization(M-1)
    B=divisors(Y)

    for p in B:
        if p>=X:
            break

        if 2<=p and check(N,p):
            X=p
print(X)
0