結果

問題 No.1006 Share an Integer
ユーザー KodaiKodai
提出日時 2020-04-16 17:29:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-09 20:59:01
合計ジャッジ時間 4,748 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 26 ms
10,880 KB
testcase_03 AC 24 ms
11,008 KB
testcase_04 AC 25 ms
10,880 KB
testcase_05 AC 25 ms
11,008 KB
testcase_06 AC 25 ms
10,880 KB
testcase_07 AC 25 ms
10,880 KB
testcase_08 AC 25 ms
11,008 KB
testcase_09 AC 26 ms
10,880 KB
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 226 ms
11,648 KB
testcase_12 AC 382 ms
11,520 KB
testcase_13 AC 403 ms
11,648 KB
testcase_14 AC 399 ms
11,648 KB
testcase_15 AC 344 ms
11,648 KB
testcase_16 AC 172 ms
11,264 KB
testcase_17 AC 230 ms
11,520 KB
testcase_18 AC 346 ms
11,648 KB
testcase_19 AC 329 ms
11,520 KB
testcase_20 AC 353 ms
11,648 KB
testcase_21 AC 399 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def f(x):
    temp = x
    count = 0
    for i in range(1, int(x**0.5)+1):
        if x % i == 0:
            count += 1
            if i != x // i:
                count += 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