結果

問題 No.546 オンリー・ワン
ユーザー roarisroaris
提出日時 2019-11-09 20:02:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 72,192 KB
最終ジャッジ日時 2024-09-15 04:47:21
合計ジャッジ時間 1,435 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

def calc(n):
    res = 0
    
    for i in range(2**N):
        l = 1
        c = 0
        
        for j in range(N):
            if (i>>j)&1:
                l = lcm(l, C[j])
                c += 1
        
        if c == 0:
            continue
        
        if c%2 == 1:
            res += n//l*c
        else:
            res -= n//l*c

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

print(calc(H)-calc(L-1))
0