結果

問題 No.1006 Share an Integer
ユーザー neterukunneterukun
提出日時 2020-03-07 13:15:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 78,532 KB
最終ジャッジ日時 2024-04-22 12:55:09
合計ジャッジ時間 5,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
74,468 KB
testcase_01 AC 73 ms
74,060 KB
testcase_02 AC 74 ms
74,548 KB
testcase_03 AC 74 ms
74,640 KB
testcase_04 AC 75 ms
74,864 KB
testcase_05 AC 89 ms
76,936 KB
testcase_06 AC 85 ms
77,236 KB
testcase_07 AC 85 ms
76,912 KB
testcase_08 AC 85 ms
77,204 KB
testcase_09 AC 85 ms
76,728 KB
testcase_10 AC 85 ms
77,176 KB
testcase_11 AC 279 ms
78,092 KB
testcase_12 AC 335 ms
78,380 KB
testcase_13 AC 347 ms
78,532 KB
testcase_14 AC 348 ms
78,460 KB
testcase_15 AC 327 ms
78,384 KB
testcase_16 AC 253 ms
78,196 KB
testcase_17 AC 282 ms
78,136 KB
testcase_18 AC 328 ms
78,084 KB
testcase_19 AC 322 ms
78,116 KB
testcase_20 AC 331 ms
78,184 KB
testcase_21 AC 346 ms
78,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    return len(divisors)


x = int(input())
memo = {}


for i in range(x // 2 - 10000, x // 2 + 10000):
    if i > 0:
        memo[i] = i - make_divisors(i)

min_val = 10 ** 9
for i in memo:
    if x - i in memo:
        min_val = min(abs(memo[x - i] - memo[i]), min_val)

ans = []
for i in memo:
    if x - i in memo and abs(memo[x - i] - memo[i]) == min_val:
        ans.append((x - i, i))
ans = sorted(ans)
for res in ans:
    print(*res)
0