結果

問題 No.546 オンリー・ワン
ユーザー kohei2019kohei2019
提出日時 2022-07-27 23:14:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 611 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 76,988 KB
最終ジャッジ日時 2023-09-24 11:48:25
合計ジャッジ時間 2,278 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,196 KB
testcase_01 AC 75 ms
71,648 KB
testcase_02 AC 74 ms
71,252 KB
testcase_03 AC 75 ms
71,424 KB
testcase_04 AC 75 ms
71,100 KB
testcase_05 AC 74 ms
71,412 KB
testcase_06 AC 74 ms
71,612 KB
testcase_07 AC 88 ms
76,524 KB
testcase_08 AC 87 ms
76,616 KB
testcase_09 AC 98 ms
76,988 KB
testcase_10 AC 93 ms
76,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N,L,H = map(int,input().split())
# bit表現
lsC = list(map(int,input().split()))

dp = [0]*(2**N)

def ls_lcm(ls):
    ret = ls[0]
    for j in range(1,len(ls)):
        gcd = math.gcd(ret,ls[j])
        ret = ret*ls[j]//gcd
    return ret

for i in range(1,2**N):
    ll = []
    for j in range(N):
        if (i >> j) & 1:
            ll.append(lsC[j])
    lcm = ls_lcm(ll)
    cnt = H//lcm-(L-1)//lcm
    dp[i] = cnt

# 包除原理で数え上げ
ans = 0
for i in range(1,2**N):
    s = bin(i)[2:].count('1')
    if s % 2 == 1:
        ans += dp[i]*s
    else:
        ans -= dp[i]*s
print(ans)
0