結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-27 23:14:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 611 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 69,724 KB |
| 最終ジャッジ日時 | 2024-07-17 12:42:46 |
| 合計ジャッジ時間 | 1,970 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
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)