結果

問題 No.1006 Share an Integer
ユーザー Mine
提出日時 2020-09-09 15:38:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 93,164 KB
最終ジャッジ日時 2024-12-15 06:58:28
合計ジャッジ時間 10,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
def Sieve_of_Eratosthenes(maxA):
    lst = [-1]*(maxA+1)
    lst[0] = 0
    lst[1] = 1
    for i in range(2, maxA+1):
        if lst[i] == -1:
            for g in range(i, maxA+1, i):
                if lst[g] == -1:
                    lst[g] = i
    return lst

def factorization(n):
    d = defaultdict(int)
    now = n
    while True:
        if now == lst[now]:
            if now != 1:
                d[now] += 1
            break
        r = lst[now]
        while now % r == 0:
            now //= r
            d[r] += 1
    ans = 1
    for i, m in d.items():
        ans *= (m+1)
    return ans

x = int(input())
lst = Sieve_of_Eratosthenes(x)

MIN = float("inf")
ans_list = []
for i in range(1, x//2+1):
    a = i
    b = x-i
    fa = a-factorization(a)
    fb = b-factorization(b)
    dif = abs(fa-fb)
    if MIN > dif:
        MIN = dif
        ans_list = []
        ans_list.append((a, b))
    elif MIN == dif:
        ans_list.append((a, b))


for a, b in ans_list:
    if a == b:
        break
    print(a, b)
for a, b in ans_list[::-1]:
    print(b, a)
0