結果

問題 No.1006 Share an Integer
ユーザー chielochielo
提出日時 2020-03-06 21:57:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 128,512 KB
最終ジャッジ日時 2024-04-22 07:33:16
合計ジャッジ時間 8,034 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 250 ms
127,960 KB
testcase_01 AC 255 ms
127,744 KB
testcase_02 AC 237 ms
128,108 KB
testcase_03 AC 240 ms
128,212 KB
testcase_04 AC 240 ms
127,872 KB
testcase_05 AC 242 ms
128,128 KB
testcase_06 AC 244 ms
128,384 KB
testcase_07 AC 240 ms
128,256 KB
testcase_08 AC 240 ms
127,872 KB
testcase_09 AC 245 ms
127,828 KB
testcase_10 AC 251 ms
128,256 KB
testcase_11 AC 260 ms
128,384 KB
testcase_12 AC 274 ms
128,424 KB
testcase_13 AC 274 ms
128,000 KB
testcase_14 AC 285 ms
128,128 KB
testcase_15 AC 263 ms
127,616 KB
testcase_16 AC 256 ms
127,956 KB
testcase_17 AC 259 ms
127,616 KB
testcase_18 AC 281 ms
128,512 KB
testcase_19 AC 283 ms
128,400 KB
testcase_20 AC 269 ms
128,000 KB
testcase_21 AC 266 ms
128,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

maxn = 2 * 10 ** 6 + 3
d = [0] * maxn
mpc = [0] * maxn
p = []
pv = [False] * maxn
d[1] = 1
for i in range(2, maxn):
    if not pv[i]:
        p.append(i)
        d[i] = 2
        mpc[i] = 1
    for j in p:
        if i * j >= maxn:
            break
        if i % j == 0:
            pv[i * j] = True
            mpc[i * j] = mpc[i] + 1
            d[i * j] = d[i] // mpc[i * j] * (mpc[i * j] + 1)
            break
        else:
            pv[i * j] = True
            mpc[i * j] = 1
            d[i * j] = 2 * d[i]

f = lambda n: n - d[n]

x = int(input())
ans = 10 ** 18
al = []
for i in range(1, x):
    a, b = i, x - i
    c = abs(f(a) - f(b))
    if c < ans:
        ans = c
        al = [(a, b)]
    elif c == ans:
        al.append((a, b))

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