結果

問題 No.1006 Share an Integer
ユーザー FromBooskaFromBooska
提出日時 2023-09-24 08:33:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 90,156 KB
最終ジャッジ日時 2023-09-24 08:33:39
合計ジャッジ時間 5,198 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,480 KB
testcase_01 AC 73 ms
71,100 KB
testcase_02 AC 81 ms
76,188 KB
testcase_03 AC 72 ms
71,272 KB
testcase_04 AC 81 ms
75,780 KB
testcase_05 AC 86 ms
76,020 KB
testcase_06 AC 84 ms
76,316 KB
testcase_07 AC 86 ms
76,316 KB
testcase_08 AC 83 ms
76,064 KB
testcase_09 AC 85 ms
75,992 KB
testcase_10 AC 84 ms
76,324 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 #

# X<2*10**6と小さいので全探索して間に合うのでは

X = int(input())
count = [0]*(X+1)

def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for x in range(1, X+1):
    calc = len(divisors(x))
    count[x] = calc

ans_list = []
mn = 10**10

for i in range(1, X):
    j = X-i
    if i > j:
        break
    
    calc = abs(i-count[i]-j+count[j])
    #print('i', i, 'j', j, 'calc', calc)
    if calc < mn:
        mn = calc
        if i != j:
            ans_list = [(i, j), (j, i)]
        else:
            ans_list = [(i, j)]
    elif calc == mn:
        if i != j:
            ans_list.append((i, j))
            ans_list.append((j, i))
        else:
            ans_list.append((i, j))
        
ans_list.sort()
#print(mn)
#print(ans_list)

for i, j in ans_list:
    print(i, j)
0