結果

問題 No.1006 Share an Integer
ユーザー 👑 KazunKazun
提出日時 2021-02-19 20:12:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 674 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 86,588 KB
実行使用メモリ 108,656 KB
最終ジャッジ日時 2023-10-14 22:31:13
合計ジャッジ時間 9,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,356 KB
testcase_01 AC 69 ms
71,448 KB
testcase_02 AC 74 ms
75,756 KB
testcase_03 AC 69 ms
71,312 KB
testcase_04 AC 78 ms
76,252 KB
testcase_05 AC 84 ms
76,564 KB
testcase_06 AC 83 ms
76,628 KB
testcase_07 AC 86 ms
76,564 KB
testcase_08 AC 84 ms
76,600 KB
testcase_09 AC 83 ms
76,604 KB
testcase_10 AC 82 ms
76,484 KB
testcase_11 AC 407 ms
94,696 KB
testcase_12 AC 632 ms
106,720 KB
testcase_13 AC 674 ms
108,656 KB
testcase_14 AC 645 ms
108,540 KB
testcase_15 AC 576 ms
104,128 KB
testcase_16 AC 327 ms
90,572 KB
testcase_17 AC 411 ms
95,164 KB
testcase_18 AC 568 ms
104,212 KB
testcase_19 AC 557 ms
103,280 KB
testcase_20 AC 597 ms
104,920 KB
testcase_21 AC 646 ms
108,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Smallest_Prime_Factor(N):
    """0,1,2,...,Nの最小の素因数のリスト(0,1については1にしている)
    """

    if N==0:
        return [1]

    N=abs(N)
    L=list(range(N+1))
    L[0]=L[1]=1

    x=4
    while x<=N:
        L[x]=2
        x+=2

    x=9
    while x<=N:
        if L[x]==x:
            L[x]=3
        x+=6

    x=5
    Flag=True
    while x*x<=N:
        if L[x]==x:
            y=x*x
            while y<=N:
                if L[y]==y:
                    L[y]=x
                y+=x<<1
        x+=2 if Flag else 4

    return L

def Faster_Prime_Factorization(N,L):
    """

    L:Smallest_Prime_Factors(N)で求めたリスト
    """
    N=abs(N)

    D=[]
    while N>1:
        a=L[N]
        k=0
        while L[N]==a:
            k+=1
            N//=a
        D.append([a,k])
    return D
#================================================
import sys
write=sys.stdout.write

X=int(input())
L=Smallest_Prime_Factor(X)

f=[0]*(X+1)
for x in range(1,X+1):
    T=Faster_Prime_Factorization(x,L)
    m=1
    for p,e in T:
        m*=e+1
    f[x]=x-m

Min=float("inf")
for A in range(1,X):
    B=X-A
    Min=min(Min,abs(f[A]-f[B]))

for A in range(1,X):
    B=X-A
    if abs(f[A]-f[B])==Min:
        write("{} {}\n".format(A,B))
0