結果

問題 No.546 オンリー・ワン
コンテスト
ユーザー brthyyjp
提出日時 2021-12-08 14:33:03
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 518 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 161 ms
コンパイル使用メモリ 84,864 KB
実行使用メモリ 71,296 KB
最終ジャッジ日時 2026-03-30 20:11:24
合計ジャッジ時間 1,283 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n, l, h = map(int, input().split())
C = list(map(int, input().split()))

ans = 0
for i in range(1<<n):
    X = []
    for j in range(n):
        if (i>>j)&1:
            X.append(C[j])
    if not X:
        continue
    y = lcm_list(X)
    cnt = h//y-(l-1)//y
    if len(X)%2 == 0:
        ans -= cnt*len(X)
    else:
        ans += cnt*len(X)
print(ans)
0