結果

問題 No.1006 Share an Integer
ユーザー FromBooskaFromBooska
提出日時 2023-03-15 21:46:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 61,424 KB
最終ジャッジ日時 2023-10-18 12:35:22
合計ジャッジ時間 2,255 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,440 KB
testcase_01 AC 37 ms
53,440 KB
testcase_02 AC 42 ms
59,372 KB
testcase_03 AC 36 ms
53,440 KB
testcase_04 AC 43 ms
59,372 KB
testcase_05 AC 43 ms
59,372 KB
testcase_06 AC 45 ms
61,424 KB
testcase_07 AC 45 ms
61,424 KB
testcase_08 AC 43 ms
59,376 KB
testcase_09 AC 48 ms
61,420 KB
testcase_10 AC 44 ms
59,372 KB
testcase_11 AC 66 ms
61,424 KB
testcase_12 AC 73 ms
61,424 KB
testcase_13 AC 73 ms
61,424 KB
testcase_14 AC 73 ms
61,424 KB
testcase_15 AC 71 ms
61,424 KB
testcase_16 AC 63 ms
61,424 KB
testcase_17 AC 66 ms
61,424 KB
testcase_18 AC 71 ms
61,424 KB
testcase_19 AC 70 ms
61,424 KB
testcase_20 AC 72 ms
61,424 KB
testcase_21 AC 74 ms
61,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Xまでの約数全列挙をしていて間に合うのだろうか
# やはりTLEした
# しかし例を見れば明らかなようにX//2付近にしか解はない

# 約数個数def
def divisor_count(n):
    count = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            count += 1
            if i != n // i:
                count += 1
        i += 1
    return count

X = int(input())

mn = 10**10
mn_set = set()
howmany = 1000
for a in range(X//2, max(0, X//2-howmany), -1):
    b = X - a
    calc = abs(a - divisor_count(a) - b + divisor_count(b))
    if calc < mn:
        mn = calc
        mn_set = set()
        mn_set.add((a, b))
        mn_set.add((b, a))
    elif calc == mn:
        mn_set.add((a, b))
        mn_set.add((b, a))
mn_list = sorted(list(mn_set))
        
#print(mn_list)
#print('mn', mn)

for a, b in mn_list:
    print(a, b)
0