結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-07-14 22:59:27 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                RE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 585 bytes | 
| コンパイル時間 | 466 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 11,392 KB | 
| 最終ジャッジ日時 | 2024-10-07 23:24:46 | 
| 合計ジャッジ時間 | 1,372 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | RE * 4 | 
| other | RE * 7 | 
ソースコード
import fractions
N, L, H = map(int, input().split())
Cs = list(map(int, input().split()))
def solve(N, L, H, Cs):
    return solve_core(N, H, Cs) - solve_core(N, L - 1, Cs)
def solve_core(N, H, Cs):
    if H == 0: return 0
    ans = 0
    for pat in range(1, 1 << N):
        lcm = calc_lcm(pat, Cs)
        n = bin(pat).count('1')
        ans += (-1) ** (n - 1) * (H // lcm) * n
    return ans
def calc_lcm(pat, Cs):
    lcm = 1
    for i, c in enumerate(Cs):
        if pat & (1 << i):
            lcm = lcm * c // fractions.gcd(lcm, c)
    return lcm
print(solve(N, L, H, Cs))
            
            
            
        