結果

問題 No.546 オンリー・ワン
ユーザー roarisroaris
提出日時 2019-11-09 20:02:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 77,272 KB
最終ジャッジ日時 2023-10-13 07:30:24
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,368 KB
testcase_01 AC 71 ms
71,584 KB
testcase_02 AC 70 ms
71,572 KB
testcase_03 AC 71 ms
71,452 KB
testcase_04 AC 69 ms
71,580 KB
testcase_05 AC 69 ms
71,424 KB
testcase_06 AC 77 ms
76,128 KB
testcase_07 AC 82 ms
76,176 KB
testcase_08 AC 81 ms
76,632 KB
testcase_09 AC 87 ms
76,548 KB
testcase_10 AC 93 ms
77,272 KB
権限があれば一括ダウンロードができます

ソースコード

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