結果

問題 No.1006 Share an Integer
ユーザー FromBooskaFromBooska
提出日時 2023-09-24 08:37:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,078 bytes
コンパイル時間 1,187 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 89,520 KB
最終ジャッジ日時 2023-09-24 08:37:10
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,624 KB
testcase_01 AC 75 ms
71,184 KB
testcase_02 AC 79 ms
75,524 KB
testcase_03 AC 75 ms
71,360 KB
testcase_04 AC 81 ms
75,560 KB
testcase_05 AC 84 ms
76,144 KB
testcase_06 AC 83 ms
76,308 KB
testcase_07 AC 83 ms
76,212 KB
testcase_08 AC 83 ms
76,152 KB
testcase_09 AC 83 ms
76,008 KB
testcase_10 AC 83 ms
76,156 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_count(n):
    lower_divisors , upper_divisors = 0, 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors += 1
            if i != n // i:
                upper_divisors += 1
        i += 1
    return lower_divisors + upper_divisors

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

#print(count)

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