結果

問題 No.1006 Share an Integer
ユーザー lam6er
提出日時 2025-03-20 20:30:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 91,820 KB
最終ジャッジ日時 2025-03-20 20:31:14
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

X = int(input())

max_n = X
d_counts = [0] * (max_n + 1)

# Precompute the number of divisors for each number up to X using sieve method
for d in range(1, max_n + 1):
    for i in range(d, max_n + 1, d):
        d_counts[i] += 1

min_diff = float('inf')
result = []

for A in range(1, X):
    B = X - A
    if B < 1:
        continue  # B must be positive
    
    fa = A - d_counts[A]
    fb = B - d_counts[B]
    current_diff = abs(fa - fb)
    
    if current_diff < min_diff:
        min_diff = current_diff
        result = [(A, B)]
    elif current_diff == min_diff:
        result.append((A, B))

# Sort the results by A in ascending order
result.sort()

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