結果

問題 No.719 Coprime
ユーザー shotoyooshotoyoo
提出日時 2021-05-25 23:10:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 3,000 ms
コード長 1,409 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2024-04-22 14:54:09
合計ジャッジ時間 4,730 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,096 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 36 ms
52,096 KB
testcase_03 AC 37 ms
52,352 KB
testcase_04 AC 37 ms
52,528 KB
testcase_05 AC 35 ms
52,224 KB
testcase_06 AC 37 ms
52,352 KB
testcase_07 AC 36 ms
52,460 KB
testcase_08 AC 37 ms
51,968 KB
testcase_09 AC 37 ms
52,736 KB
testcase_10 AC 38 ms
52,480 KB
testcase_11 AC 36 ms
52,224 KB
testcase_12 AC 36 ms
52,096 KB
testcase_13 AC 36 ms
52,864 KB
testcase_14 AC 36 ms
52,480 KB
testcase_15 AC 36 ms
52,352 KB
testcase_16 AC 38 ms
52,480 KB
testcase_17 AC 38 ms
52,608 KB
testcase_18 AC 38 ms
52,484 KB
testcase_19 AC 36 ms
52,480 KB
testcase_20 AC 38 ms
52,480 KB
testcase_21 AC 37 ms
52,352 KB
testcase_22 AC 39 ms
52,480 KB
testcase_23 AC 38 ms
52,224 KB
testcase_24 AC 38 ms
52,096 KB
testcase_25 AC 37 ms
52,224 KB
testcase_26 AC 37 ms
52,992 KB
testcase_27 AC 38 ms
52,480 KB
testcase_28 AC 38 ms
52,224 KB
testcase_29 AC 38 ms
52,224 KB
testcase_30 AC 37 ms
52,864 KB
testcase_31 AC 37 ms
52,480 KB
testcase_32 AC 37 ms
52,480 KB
testcase_33 AC 37 ms
52,860 KB
testcase_34 AC 37 ms
52,608 KB
testcase_35 AC 36 ms
52,480 KB
testcase_36 AC 37 ms
52,608 KB
testcase_37 AC 37 ms
52,224 KB
testcase_38 AC 35 ms
52,608 KB
testcase_39 AC 37 ms
52,608 KB
testcase_40 AC 36 ms
52,608 KB
testcase_41 AC 38 ms
52,736 KB
testcase_42 AC 37 ms
52,352 KB
testcase_43 AC 43 ms
59,520 KB
testcase_44 AC 43 ms
59,776 KB
testcase_45 AC 46 ms
60,928 KB
testcase_46 AC 46 ms
61,184 KB
testcase_47 AC 46 ms
60,928 KB
testcase_48 AC 46 ms
61,184 KB
testcase_49 AC 47 ms
61,824 KB
testcase_50 AC 49 ms
61,824 KB
testcase_51 AC 48 ms
62,592 KB
testcase_52 AC 53 ms
64,896 KB
testcase_53 AC 65 ms
69,888 KB
testcase_54 AC 73 ms
72,832 KB
testcase_55 AC 73 ms
73,472 KB
testcase_56 AC 95 ms
76,928 KB
testcase_57 AC 92 ms
77,164 KB
testcase_58 AC 101 ms
76,928 KB
testcase_59 AC 100 ms
77,184 KB
testcase_60 AC 103 ms
77,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

def hurui(n):
    """線形篩
    pl: 素数のリスト
    mpf: iを割り切る最小の素因数
    """
    pl = []
    mpf = [None]*(n+1)
    for d in range(2,n+1):
        if mpf[d] is None:
            mpf[d] = d
            pl.append(d)
        for p in pl:
            if p*d>n or p>mpf[d]:
                break
            mpf[p*d] = p
    return pl, mpf
def factor(num):
    d = {}
    if num==1:
        return {1:1}
    while num>1:
        d.setdefault(mpf[num], 0)
        d[mpf[num]] += 1
        num //= mpf[num]
    return d
n = int(input())
pl, mpf = hurui(n)
index = {}
ps = [item for item in pl if item*item<=n]
m = len(ps)
for i,p in enumerate(ps):
    index[p] = i
dp = [0]*(1<<m)
for i in range(len(pl)):
    p = pl[i]
    ndp = dp[:]
    for v in range(p, n+1, p):
        vp = v//p
        f = factor(vp)
        if max(f.keys())>p:
            continue
        b0 = 0
        for j in range(m):
            if v%ps[j]==0:
                b0 |= 1<<j
#         print(v,f,b0)
        for b in range(1<<m):
            if b&b0:
                continue
            ndp[b|b0] = max(ndp[b|b0], dp[b]+v)
    dp = ndp
#     print(p, dp)
ans = max(dp)
print(ans)
0