結果

問題 No.546 オンリー・ワン
ユーザー ああいい
提出日時 2022-03-08 14:42:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 67,904 KB
最終ジャッジ日時 2024-07-23 14:25:44
合計ジャッジ時間 1,342 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def calc(x):
    return H // x - (L-1) // x
def gcd(a,b):
    while True:
        r = a % b
        a = b
        b = r
        if r == 0:return a
def lcm(a,b):
    return a * b // gcd(a,b)

ans = 0
for bit in range(1,1 << N):
    d = 1
    flag = True
    for i in range(N):
        if bit & (1 << i):
            d = lcm(d,C[i])
            if d > H:
                flag = False
                break
    if flag:
        u = bin(bit).count('1')
        if u % 2 == 0:
            u = -u
        ans += u * calc(d)
print(ans)

0