結果

問題 No.546 オンリー・ワン
ユーザー norioc
提出日時 2025-03-18 00:09:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 3,351 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 69,144 KB
最終ジャッジ日時 2025-03-18 00:09:38
合計ジャッジ時間 1,811 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import lcm


def f(x, vs):
    sz = len(vs)
    cnt = [0] * (1 << sz)

    for i in range(1 << sz):
        l = 1
        for j in range(sz):
            if i & (1 << j):
                l = lcm(l, vs[j])

        cnt[i] = x // l

    for i in range(sz):
        for j in range(1 << sz):
            if ~j & (1 << i):
                cnt[j | (1 << i)] -= cnt[j]

    res = 0
    for i in range(sz):
        u = ((1 << sz) - 1) ^ (1 << i)
        v = ((1 << sz) - 1)
        res += abs(cnt[u]) - abs(cnt[v])

    return res


N, L, H = map(int, input().split())
C = list(map(int, input().split()))

ans = f(H, C) - f(L-1, C)
print(ans)
0