結果
問題 | No.1006 Share an Integer |
ユーザー |
![]() |
提出日時 | 2023-09-24 08:37:04 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,078 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 82,568 KB |
実行使用メモリ | 91,032 KB |
最終ジャッジ日時 | 2024-07-17 09:00:41 |
合計ジャッジ時間 | 4,402 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 TLE * 1 -- * 10 |
ソースコード
# 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)