結果

問題 No.1006 Share an Integer
ユーザー ntuda
提出日時 2024-09-01 20:27:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,238 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 265,268 KB
最終ジャッジ日時 2024-09-01 20:27:39
合計ジャッジ時間 4,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def seachPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

def adic(dic,x):
    if x in dic:
        dic[x] += 1
    else:
        dic[x] = 1
    return

def factorization(x):
    dic = {}
    for p in PL:
        if x in PL:
            adic(dic,x)
            return dic
        while x % p == 0:
            adic(dic,p)
            x //= p
        if x == 1:
            return dic

# 約数の数
def N_divisors(x):
    dic = factorization(x)
    ret = 1
    for v in dic.values():
        ret *= (v+1)
    return ret

X = int(input())
PL = seachPrimeNum(X)

L = []
difmin = X
for A in range(1,X//2+1):
    B = X - A
    FA = A - N_divisors(A)
    FB = B - N_divisors(B)
    if abs(FA-FB) < difmin:
        difmin = abs(FA-FB)
        L = [A]
    elif abs(FA-FB) == difmin:
        L.append(A)
ans = []
for l in L:
    if X % 2 == 0 and X//2 == l:
        ans.append((l,l))
    else:
        ans.append((l,X-l))
        ans.append((X-l,l))
ans.sort()
for a in ans:
    print(*a)



0