結果

問題 No.1006 Share an Integer
ユーザー toyuzuko
提出日時 2020-03-09 00:38:50
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,161 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-07 20:20:47
合計ジャッジ時間 12,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

def factorization(n):
    if n == 1: return [1]
    res = []
    x = n
    y = 2
    while y * y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1: res.append(x)
    return res

def val(n):
    if n == 1: return 0
    f = factorization(n)
    C = Counter(f)
    tmp = 1
    for v in C.values():
        tmp *= v + 1
    return n - tmp

X = int(input())

ans = []
minf = 10**18

for i in range(1, X):
    if abs(i - (X - i)) > 10000:
        continue
    dif = abs(val(i) - val(X - i))
    
    if  dif == minf:
        ans.append((i, X - i))
    elif dif < minf:
        ans = [(i, X - i)]
        minf = dif
    else:
        pass

for a in ans:
    print(*a)
0