結果

問題 No.1006 Share an Integer
ユーザー Kodai
提出日時 2020-04-16 17:07:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,956 KB
最終ジャッジ日時 2024-10-01 20:37:54
合計ジャッジ時間 4,077 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def f(x):
    temp = x
    count_dict = {}
    while True:
        if x == 1:
            break
        for i in range(2, x+1):
            if x % i == 0:
                if i not in count_dict:
                    count_dict[i] = 1
                else:
                    count_dict[i] += 1
                x //= i
                break
    count = 1
    for i in count_dict.values():
        count *= (i+1)
    return temp-count


def difference(x, y):
    return abs(f(x)-f(y))


X = int(input())

temp_dict = {}

start = math.floor(X//2-2*(2*math.sqrt(X)+1))
if start < 1:
    start = 1

for i in range(start, X//2+1):
    if abs(i-(X-i)) <= 2*(2*math.sqrt(X)+1):
        diff = difference(i, X-i)
        if diff not in temp_dict:
            temp_dict[diff] = [[i, X-i]]
        else:
            temp_dict[diff].append([i, X-i])

min_key = min(temp_dict.keys())
for data in temp_dict[min_key]:
    print(data[0], data[1])
for data in temp_dict[min_key][::-1]:
    if data[1] != data[0]:
        print(data[1], data[0])
0