結果

問題 No.1006 Share an Integer
ユーザー KodaiKodai
提出日時 2020-04-16 17:07:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,076 KB
最終ジャッジ日時 2024-04-09 20:20:19
合計ジャッジ時間 4,009 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,076 KB
testcase_01 AC 27 ms
11,008 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 25 ms
11,008 KB
testcase_04 AC 27 ms
11,008 KB
testcase_05 AC 27 ms
11,008 KB
testcase_06 AC 26 ms
10,880 KB
testcase_07 AC 27 ms
11,008 KB
testcase_08 AC 25 ms
11,008 KB
testcase_09 AC 27 ms
11,008 KB
testcase_10 AC 26 ms
11,008 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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