結果
| 問題 | No.546 オンリー・ワン |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-27 23:14:29 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 611 bytes |
| 記録 | |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 68,480 KB |
| 最終ジャッジ日時 | 2026-04-01 03:28:26 |
| 合計ジャッジ時間 | 1,314 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)